1

I have an online game system. I issue some tokens through ethereum. How can I peg value of the tokens issued on ethereum to my game system, which is outside the ethereum eco system. (ie) The users need to be able to buy in game items like weapons, power ups etc. using the custom tokens.

Logically, I'm guessing it will work something like this : I ask the user's their ethereum wallet public key. The user sends the tokens to my wallet. I will query ethereum using some API and figure that the user X has deposited some tokens on my wallet. When the transaction has happened, I will issue out the in game items.

Another way to look at the question is, when I sell tokens to users in an ICO, how will the user use those tokens to trade it for some value in my product.

Example code is much appreciated.

  • I don't fully follow your question and what you are trying to accomplish. Would it just be easier to accept payments in ether and credit users with an in-game, off-chain token? – lungj Oct 4 '17 at 20:56
  • I'm looking at ICOs as an alternative to kickstarter to fund my project. So the question is, if I sell tokens to users, whats in it for them ? How is a user going to benefit by holding on to a token ? How does the technical side of it look like ? – MD Luffy Oct 4 '17 at 21:11
  • What the benefit to the token buyers is whatever you give them in exchange for the tokens. For example, a subway token in Toronto can be used to ride our subway. Once you have bought one, even if the price of tokens increase, your token can still be used to ride the subway. So its value is pegged to the value of riding the subway. You could offer an in-game 100% health booster for 5 tokens. And then that’s what the value of the tokens is. That’s a possible benefit for token holders. – lungj Oct 4 '17 at 22:33
  • With a crowdfunding model, you could say that, for a promo period, people can get 150 tokens per ether. After your crowdfunding period, you only give 100 tokens per ether. That’s the benefit for participating in your crowdsale. There may be no benefit to holding tokens. That’s dictated by economics and is largely out of your control. If your game is not popular, someone may be willing to sell their tokens for pennies on the dollar because they just don’t care enough to play. Or you overprice your in game items. – lungj Oct 4 '17 at 22:38
  • The participants in Ethereum’s initial sale got over 1000 ETH per bitcoin and look like geniuses now. But ethereum could have just as easily gone bust. Like people who picked up dogecoin at 0.2 US cents each. – lungj Oct 4 '17 at 22:44
0

Once you have distributed tokens out through an ICO, you would then write code in your application that requires said tokens. What the tokens are traded for is entirely up to you and dependent on the parameters of the application you are building.

The contract code for the token you create will include a sendCoin() function of some kind that sends tokens between Ethereum addresses. So in the code you would specify an address for collecting tokens in the game and users would then send tokens to that address in a transaction on the Ethereum chain. Sending the tokens will require an up to date Ethereum node (to access the token contract code and send a transaction), so users in your game would have to have a local updated node on their system, or maybe you could just have a remote node up and running that they connect to centrally (if you don't care about have decentralization in your game).

Here's probably the real catch that there's no easy solution already figured out--until that transaction including the sent tokens is processed there is no way to tell that they have sent you tokens (at least by scanning the blockchain). Each new block takes about 13 seconds to mine, so thats the bare minimum time the user will have to wait to collect whatever they are buying. You could just log their purchases and check their balances (no wait time) and then give them the item before the transaction is mined. There's a lot of ways to about doing this, and they can't all be covered in one question.

I will say lastly that make sure the game you are building is decentralized in some way, otherwise there is no point in using tokens built on Ethereum.

EDIT: Forgot to mention, sending tokens to another Ethereum address will require some amount of ether in the sending account (however much the gas cost of the sendCoin() function is). So if they are running a local Ethereum node they would need some ether in their account.

  • Lets say the transaction went through. How would I detect this from my game code. – MD Luffy Oct 4 '17 at 20:13
  • Your game code would have to interact with the Ethereum chain. On top of a sendCoin() function you would need a coinBalanceOf() function that returns the balance for a given address. Once the transaction goes through, the game can query the blockchain for balances to check if the user payed the tokens required. You would also need storage in your token contract for the balances. – jojeyh Oct 4 '17 at 22:49
0

You can use ERC20 transfer events to the designated receiver address

(Or make a special smart contract with a buy, and buyEvent )

Once the event has been sent you can grant the in-game item.

Really as simple as that. If you want a dynamic price you might want to look at the update functionality in this one: https://github.com/hunterlong/fiatcontract/blob/master/contracts/FiatContract.sol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.