[Ethereum] How to peg value to token outside ethereum

external-apitokens

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.

Best Answer

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.

Related Topic