Trustless Golem Network Token (GNT) Selling Contract

Some individuals missed out on purchasing the Golem Network Token (GNT) in the Golem Crowdfunding Funded To 820,000 ETH Cap, as the sale was over within ~ half an hour. The tokens were sold a 1 ether (ETH) = 1,000 GNTs, or 0.001 ETH per 1 GNT.

User /u/cintix on reddit.com/r/ethereum posted Trustless GNT Selling Contract stating:

I saw there was interest in a contract that sells GNT, so I made one! It sells 100,000 GNT at 2x crowdsale price. You just send ETH to it and it sends you GNT back! Be sure to check through the code and test with a small amount first!

See also Trustless GNT Selling Contract on reddit.com/r/ethtrader for many more contracts.

The code in this Trustless GNT Selling contract is based on user /u/JonnyLatte‘s code originally posted in Live testing ETH <-> Token, Atomic swap market to trade Augur REP tokens.


Table of contents


cryptoderivatives.market

Check out the first version of https://cryptoderivatives.market/, a decentralised GNT/ETH exchange contracts market.


Find GNT TokenTrader Contracts Script

I’ve just created a script to list the TokenTrader contracts – see:


Find GNT TokenTrader Contracts In Ethereum Wallet/Mist

If you want to find the TokenTrader contracts that have been created by the TokenTraderFactory contract, add the TokenTraderFactor to your Watch Contracts. To do this, click on the Contracts tab and click Watch Token. Enter the GNTTokenTraderFactory in the Contract Name field, 0xc4af56cd5254aef959d4bce2f75874007808b701 in the Contract Address field, and the following Application Binary Interace (ABI) data in the JSON Interface field and click OK:

[{"constant":false,"inputs":[{"name":"_asset","type":"address"},{"name":"_sellPrice","type":"uint256"},{"name":"_units","type":"uint256"},{"name":"_sellsTokens","type":"bool"}],"name":"createTradeContract","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"tradeContract","type":"address"}],"name":"verify","outputs":[{"name":"valid","type":"bool"},{"name":"asset","type":"address"},{"name":"sellPrice","type":"uint256"},{"name":"units","type":"uint256"},{"name":"sellsTokens","type":"bool"}],"payable":false,"type":"function"},{"payable":false,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"bookid","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"addr","type":"address"}],"name":"TradeListing","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"bookid","type":"bytes32"},{"indexed":false,"name":"asset","type":"address"},{"indexed":false,"name":"units","type":"uint256"}],"name":"NewBook","type":"event"}]

Screen-Shot-2016-11-14-at-23.32.32

Now click on the GNTTOKENTRADERFACTORY contract in the Contracts tab. Scroll down and click the checkbox for Watch contract events. You will find the list of created TokenTrader contracts – the highlighted address is the address used in the next “Watch GNT TokenTrader Contract In Ethereum Wallet/Mist” section.
Screen-Shot-2016-11-14-at-23.44.06


Watch GNT TokenTrader Contract In Ethereum Wallet/Mist

If you want to confirm the contract parameters for a TokenTrader contract in Mist, find the TokenTrader contract address your want to watch, e.g., #28 0x406a65de7a2e94ef19597a79296e269fada85a71, from the list generated in the “Find GNT TokenTrader Contracts” section above:

28 TokenTraderAddress: 0x406a65de7a2e94ef19597a79296e269fada85a71
  Deployed                   : #2624456 at Mon, 14 Nov 2016 08:39:06 UTC txHash 0x0eca65c8457f60599d55dfe8554e9232b824eba714d941d318660d7e691629af
  Owner                      : 0x45689bac94edae26625521f1361748119f05fc30
  Asset address              : 0xa74476443119a942de498590fe1f2454d7d4ac0d GNT
  Sells tokens               : true
  Sell price                 : 190
  Units                      : 100000
  Ethers per 1,000 tokens    : 1.9
  Current token balance      : 195684.2105263157895
Current ether balance : 9.952798346

Use the following ABI:

[{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"withdraw","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"asset","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"sellPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"sellsTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"withdrawAsset","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"units","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_value","type":"uint256"}],"name":"withdrawToken","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"buy","outputs":[],"payable":true,"type":"function"},{"constant":false,"inputs":[{"name":"_sellsTokens","type":"bool"}],"name":"activate","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"_asset","type":"address"},{"name":"_sellPrice","type":"uint256"},{"name":"_units","type":"uint256"},{"name":"_sellsTokens","type":"bool"}],"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sells","type":"bool"}],"name":"ActivatedEvent","type":"event"},{"anonymous":false,"inputs":[],"name":"UpdateEvent","type":"event"}]

Watch GNT Token In Ethereum Wallet/Mist

If you have not already added a Watch Token for the Golem Network Token in Ethereum Wallet / Mist, click on the Contracts tab and click on Watch Token. Enter the GNT TokenTrader address 0xa74476443119A942dE498590Fe1f2454d7D4aC0d into the Token Contract Address field as shown below, then click OK:
Screen-Shot-2016-11-14-at-23.13.19

In Ethereum Wallet / Mist, click on the Contracts tab and click on Watch Contract. I have entered the Contract Name of “GNTTokenTrader28”, the appropriate Contract Address and add the ABI above in the JSON Interface field, then click OK.
Screen-Shot-2016-11-14-at-22.56.15

In Ethereum Wallet / Mist, click on the Contracts tab and click on your newly created Watch Contract. You will see the number of GNTs that the contract is selling:
Screen-Shot-2016-11-14-at-22.59.53

Scrolling down the page, you will see the Read From Contract fields on the left side. You can find out the Sell Price (190 in contract #28), Units (100,000 in contract #28). The price per unit of GNT is 190 / 100,000 = 0.0019 ETH. The price per 1,000 GNTs is 1.9 ETH for this contract #28.
Screen-Shot-2016-11-14-at-23.06.49

If you want to, you can execute the Buy function on the right side of the screen – test with a small amount first.


Trustless GNT Token Selling Contract

Following is the verified contact source for the GNT TokenTraderFactory contract at 0xc4af56cd5254aef959d4bce2f75874007808b701. This factory contract is used to create TokenTrader contracts as deployed to 0x399156ee3339f4b29a53e307b98cce09fda3bac7 for the 2x contract, and 0x4104e4b12e73bc99dd4f20a39525d07aa395c0d4 for the 3x contract:

Following are the instructions by /u/JonnyLatte posted at Trustless GNT Selling Contract for using the contract above:

Someone has asked me how to use my contract to sell GNT. I’m going to put the reply here so that I am not repeating myself:

I gave some simple instructions for using my platform to make your own trades here

It should be fine to sell GNT however I have not tested it and it wont be able to buy GNT only sell because GNT is missing the approve() and transferFrom() functions. Since these functions are not used for selling or adding and withdrawing funds from a trade contract it should not be a problem. I have not tested this though so if you do decide to use it you should test with a small amount first.

However since OP has gone to the trouble of stripping out the missing GNT functionality and is successfully selling I may as well show how to use this contract rather than my own.

First up let me describe a trade contract and then how to create one:

A trade contract holds funds and has an owner that can withdraw those funds to their account. To deposit tokens into it you just send them to its address. To withdraw them you call its withdrawToken function giving it the address of the token and the amount in that tokens smallest units.

The trade contract can also sell one token called the asset at a fixed rate that is determined when the contract is created. For ease of use you can also withdraw that token using withdrawAsset which does not require you to specify the address of the token because that was already given when the contract was created. I have pasted a copy of the trade contract’s ABI which the owners of a trade contract can use to follow instances for withdrawing funds.

You do not deploy a trade contract directly, instead you use a factory contract which creates an instance for you given the setup. You do that by following the factory address with the factory ABI and calling the function createTradeContract.

The parameters of createTradeContract for OP’s sell only factory are:

address _asset, 
uint256 _sellPrice, 
uint256 _units,
bool    _sellsTokens
the asset is the address of the token being sold. In the
 case of GNT thats 0xa74476443119A942dE498590Fe1f2454d7D4aC0d

_sellPrice is the number of WEI the contract needs to be
 sent to send some tokens in return

_units is how many of the smallest units of the token that
 are sent in return for sending _sellPrice amounts of WEI

_sellsTokens should be set to true if you want the
 contract to immediately accept ETH and sell the
 token or false if you want to start with selling
 deactivated for the purpose of testing (the owner
 account will be able to sell to it but no one
 else until activate(true) is called)

For example OP made the contract at 0x4104e4b12e73bc99dd4f20a39525d07aa395c0d4 selling GNT at 3x the crowd sale price. The parameters they used are:

address _asset = 0xa74476443119a942de498590fe1f2454d7d4ac0d (GNT)
uint256 _sellPrice = 300
uint256 _units = 100000
bool    _sellsTokens = true

I would suggest sticking with their choice of units and adjusting _sellPrice to fit whatever price level you want: 100 for the same price as the crowd sale 200 for double etc.

If you successfully create a trade contract the factory will fire off an event showing the address and owner. You can also see them at https://etherscan.io/address/0xc4af56cd5254aef959d4bce2f75874007808b701#internaltx and then follow the one you think is yours double checking you are the owner.


The Original Trustless REP Token Trading Contract

Following is the verified contact source for the original Augur REP TokenTraderFactory contract at 0x3398080b81a1cff1429af347ce2b17fc28de3937 by /u/JonnyLatte. This factory contract then creates the TokenTrader contract as deployed to 0x399156ee3339f4b29a53e307b98cce09fda3bac7. See The Original Augur REP TokenTraderFactory Contract for further information on this contract:

This entry was posted in Blog and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.