Using the DGD Swap contract — From Attores

Attores Pte Ltd
4 min readMay 7, 2016

--

Good news everyone! We have open sourced the code for an escrow Swap Contract for the Digix Crowdsale tokens, abbreviated as DGD tokens. You can find it at this link: https://github.com/gaurangtorvekar/DGD-Swap-Contract/blob/master/DGD_Swap.sol

Checksum current version 0.2 / md5: 7f1d8beaaf713ac5b0aa26c4cd2804be

Older versions will have checksum at the bottom of the page.

While several exchanges might list these tokens, there are many users who want the functionality of a OTC (Over the Counter) swap. Others might not want to pay the fees on the exchanges, or just want to speculate on the future price.

Swapping the tokens in this manner is a 3-step process.

  1. Create a Swap contract with your desired price
  2. Approve the swap contract to transact on your behalf from the the Digix contract (only if the other side is matched)
  3. Get the other party to send Ether to this contract

Step 1 — To create a Swap contract

In your Mist (Ethereum-Wallet), go to Contracts > Deploy New Contract

In the text box for ‘Solidity Contract Source Code’, copy paste the code from the file DGD_Swap.sol from the GitHub link — https://github.com/gaurangtorvekar/DGD-Swap-Contract/blob/master/DGD_Swap.sol

Under amount, put in the amount of 0.01 to 0.05 for gas costs of the contract execution. (under the current code, the contract won’t send you back any remaining ether, we are unsure of the gas you will need as you may have many or few transactions. You may need to top up.)

On the right hand panel, in the ‘Constructor parameters’, enter the token address of the DGD Token contract, which is — 0xe0b7927c4af23765cb51314a0e0521a9645f0e2a

Morden Testnet DGD token address: 0x3c6f5633b30aa3817fa50b17e5bd30fb49bddd95

Put beneficiary as any of your own Wallet addresses where you want to receive the Ether.

Then enter whatever price you want for your token(please note that this price is in Finney. 1 Ether = 1000 Finney, so if you want 0.75 ether for your token you would enter 750)

The ‘expiration in days’ field is in case no one matches your order, you’ll get the token back. Any ether sent after this date will not be accepted by the contract.

After the contract has been deployed and confirmed, you can get the contract address. You may want to rename it.

Step 2 — Transfer tokens to this Swap Contract

You can start watching the DGD token contract by copy pasting the abi code Token.json from this link: https://gist.githubusercontent.com/tymat/11887bc55c6670c92902f46a874cd6fd/raw/1c258e340383c257dc4b775962aa2d70da4c2675/Token.json

and putting the token address: 0xe0b7927c4af23765cb51314a0e0521a9645f0e2a

‘Approve’ the contract from YOUR address which owns the tokens to the Swap Contract you just created.

To check that the Swap Contract has been given approval to transfer your tokens, after you Approved the Swap Contract, you should be able to see the amount of approved tokens in the ‘Remaining’ section of the token contract — Enter the beneficiary address, and the swap contract address.

Check if the swap has been given approval over your DGD (in the watched DGD contract)

Step 3 — Get Ether from the second party

Now you can ask the buyer to send Ether to this Swap contract. This sender will get the appropriate amount of tokens and you will get the Ether in your ‘beneficiary’ account that you entered earlier

  • In order to view the DGD tokens in your MIST wallet, you will need to follow the DIGIX guide.

version 0.1 / md5: 75cebe47a4f89d2d726c2781fc5afec7

Visit Attores.com for more contracts, and our upcoming Smart Contracts as a Service platform.

--

--