• Complain

Chris Dannen - Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers

Here you can read online Chris Dannen - Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Chris Dannen Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers
  • Book:
    Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2018
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Learn how to take your existing knowledge of Ethereum and Solidity to the next level. Hone your development skills and become more familiar with the syntax of the Solidity language by working through well-tested, well-documented intermediate-level sample projects.

You will begin by covering the basics of Ethereum, Solidity, and gaming theory. From there, you will move onto sample projects that use smart contract engineering to create fun casino-style games that you can deploy and test on your friends and colleagues with real ether. All games are provably fair and auditable, so that players know the house wont always win!

Ideal for any reader with exposure to Ethereum, the techniques this book teaches are applicable to game developers, software engineers, web developers, and cryptocurrency enthusiasts.

What Youll Learn

  • Use various features and best practices for smart contract programming in Ethereum and Solidity
  • Develop and deploy games of chance, similar to the kind youd find in a casino
  • Create fun, easy projects with Ethereum
  • lntegrate the Ethereum blockchain into games

Who This Book Is For

Entry-level programmers with some exposure to Ethereum; game developers, Blockchain and cryptocurrency enthusiasts looking to add Ethereum and Solidity development to their skill set; software engineers and Web developers

Chris Dannen: author's other books


Who wrote Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers? Find out the surname, the name of the author of the book and a list of all author's works by series.

Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make

Kedar Iyer and Chris Dannen 2018

Kedar Iyer and Chris Dannen , Building Games with Ethereum Smart Contracts ,

10. Prediction Markets

Kedar Iyer 1 and Chris Dannen 1

(1) Brooklyn, New York, USA

On the gambling spectrum, prediction markets are somewhere between proposition bets (prop bets) and stock markets. They dont enjoy the full legitimacy of stock markets, but they tend to be less silly and address more serious matters than your standard prop bet. Prediction markets start by posing a yes/no question about a future event with a verifiable answer. Users can then bet on the possibility of the event by buying or selling shares in the market.

Here is an example of a typical prediction market question:

Will Ethereum trade at $2,000 or higher on GDAX on January 1, 2019 00:00.000 UTC?

This is a clear question with a publicly verifiable answer ending at an exact time. Good prediction market questions eliminate all sources of ambiguity so that users can verify and track the state of their bet.

The format of this chapter is slightly different from previous chapters. Instead of presenting multiple contracts, we spend the majority of the chapter walking through a complex prediction market contract. At the end, we cover resolution methods that you will be free to implement on your own.

Contract Overview

In a prediction market, trading is split into shares . Each share pays out 100 wei if the answer resolves to Yes, and 0 wei if the answer resolves to No. In this way, the price per share reflects the markets possibility of resolving to Yes. If the price for the preceding market is 60, the market thinks theres a 60% probability that Ethereum will be above $2,000 at the beginning of 2019.

To start a market, a market creator must post collateral for the payouts, 100 wei for each share. If the market resolves to Yes, the collateral is paid out to the owners of the shares. If the market resolves to No, the collateral is paid back to the market creator. In exchange for taking on this risk, the market creator is allowed to charge a fee on every trade. Typical fees on cryptocurrency exchanges are between 0.1% and 0.25%. Our contract will charge 0.2% on each side of a trade, but this can be changed easily.

The full contract is presented in Listing , with commentary and analysis to follow.

Listing 10-1 Prediction Market
contract PredictionMarket {
enum OrderType { Buy, Sell }
enum Result { Open, Yes, No }
struct Order {
address user;
OrderType orderType;
uint amount;
uint price;
}
uint public constant TX_FEE_NUMERATOR = 1;
uint public constant TX_FEE_DENOMINATOR = 500;
address public owner;
Result public result;
uint public deadline;
uint public counter;
uint public collateral;
mapping(uint => Order) public orders;
mapping(address => uint) public shares;
mapping(address => uint) public balances;
event OrderPlaced(uint orderId, address user, OrderType orderType, uint amount, uint price);
event TradeMatched(uint orderId, address user, uint amount);
event OrderCanceled(uint orderId);
event Payout(address user, uint amount);
function PredictionMarket (uint duration) public payable {
require(msg.value > 0);
owner = msg.sender;
deadline = now + duration;
shares[msg.sender] = msg.value / 100;
collateral = msg.value;
}
function orderBuy (uint price) public payable {
require(now < deadline);
require(msg.value > 0);
require(price >= 0);
require(price <= 100);
uint amount = msg.value / price;
counter++;
orders[counter] = Order(msg.sender, OrderType.Buy, amount, price);
OrderPlaced(counter, msg.sender, OrderType.Buy, amount, price);
}
function orderSell (uint price, uint amount) public {
require(now < deadline);
require(shares[msg.sender] >= amount);
require(price >= 0);
require(price <= 100);
shares[msg.sender] -= amount;
counter++;
orders[counter] = Order(msg.sender, OrderType.Sell, amount,
price);
OrderPlaced(counter, msg.sender, OrderType.Sell, amount, price);
}
function tradeBuy (uint orderId) public payable {
Order storage order = orders[orderId];
require(now < deadline);
require(order.user != msg.sender);
require(order.orderType == OrderType.Sell);
require(order.amount > 0);
require(msg.value > 0);
require(msg.value <= order.amount * order.price);
uint amount = msg.value / order.price;
uint fee = (amount * order.price) * TX_FEE_NUMERATOR /
TX_FEE_DENOMINATOR;
uint feeShares = amount * TX_FEE_NUMERATOR / TX_FEE_DENOMINATOR;
shares[msg.sender] += (amount - feeShares);
shares[owner] += feeShares;
balances[order.user] += (amount * order.price) - fee;
balances[owner] += fee;
order.amount -= amount;
if (order.amount == 0)
delete orders[orderId];
TradeMatched(orderId, msg.sender, amount);
}
function tradeSell (uint orderId, uint amount) public {
Order storage order = orders[orderId];
require(now < deadline);
require(order.user != msg.sender);
require(order.orderType == OrderType.Buy);
require(order.amount > 0);
require(amount <= order.amount);
require(shares[msg.sender] >= amount);
uint fee = (amount * order.price) * TX_FEE_NUMERATOR /
TX_FEE_DENOMINATOR;
uint feeShares = amount * TX_FEE_NUMERATOR / TX_FEE_DENOMINATOR;
shares[msg.sender] -= amount;
shares[order.user] += (amount - feeShares);
shares[owner] += feeShares;
balances[msg.sender] += (amount * order.price) - fee;
balances[owner] += fee;
order.amount -= amount;
if (order.amount == 0)
delete orders[orderId];
TradeMatched(orderId, msg.sender, amount);
}
function cancelOrder (uint orderId) public {
Order storage order = orders[orderId];
require(order.user == msg.sender);
if (order.orderType == OrderType.Buy)
balances[msg.sender] += order.amount * order.price;
else
shares[msg.sender] += order.amount;
delete orders[orderId];
OrderCanceled(orderId);
}
function resolve (bool _result) public {
require(now > deadline);
require(msg.sender == owner);
require(result == Result.Open);
result = _result ? Result.Yes : Result.No;
if (result == Result.No)
balances[owner] += collateral;
}
function withdraw () public {
uint payout = balances[msg.sender];
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers»

Look at similar books to Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers»

Discussion, reviews of the book Building Games with Ethereum Smart Contracts: Intermediate Projects for Solidity Developers and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.