Our next contract in line is the contract for swapping Digix Gold for Ether. We have open sourced the code for an escrow Swap Contract for the Digix Gold. This is a more EFFICIENT smart contract which just needs your approval for spending your tokens on your behalf, thus reducing the TXN fees. Hence, you don’t have to actually send your tokens to the swap, just ‘approve’ it. You can find it at this link: https://github.com/gaurangtorvekar/DGX-Swap

Checksum current version 0.21/ md5: 499912c048cd684520a79639f55069bb

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

By using the OTC Swap, you eliminate counterparty risks of exchanges holding your gold tokens or ether.

Swapping the gold tokens using the contract is a 3-step process.

Create a Swap contract with your desired price Approve the swap contract to transact on your behalf from the the Digix contract (only if the other side is matched) 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 DGX_swap.sol from the GitHub link: https://github.com/gaurangtorvekar/DGX-Swap

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 DGX Gold Token contract, which is — 0x55b9a11c2e8351b4ffc7b11561148bfac9977855

(There is no testnet version of the DGX Gold contract. Please be careful while deploying to the livenet)

In ‘send ether to’ — beneficiary, put any of your own Wallet addresses where you want to receive the Ether.

Then enter the price you want for your DGX(please note that this price is in Finney. 1 Ether = 1000 Finney, so if you want 1.10 ether for your DGX you would enter 1100)

The ‘expiration in days’ field is in case no one matches your order. Any ether sent after this date will not be accepted by the contract. In this example, the contract will expire in 2 days if there is no buyer and the DGX approval will expire.

Deploying the Swap Contract

Step 2 —Approve the swap contract to transact on your behalf

You can start watching the DGX gold contract by copy pasting the abi code GoldTokenLedger.abi.json from this link: https://github.com/DigixGlobal/gold-tokens-interface

and putting the gold address: 0x55b9a11c2e8351b4ffc7b11561148bfac9977855

You should also watch the token so that you can check the allowances of the swap contract.

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

Approve the Swap Contract to move your DGX when a matching order comes in

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 DGX (in the watched DGX 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 gold tokens and you will get the Ether in your ‘beneficiary’ account that you entered earlier

Considerations

Please note that DGX transactions have a TXN fee of 0.13%, i.e., if you transfer 1 token worth 1 gram, you will be charged 0.0013 grams of Gold. We have made this particular Swap Contract more efficient than the DGD Token Swap and DGD Badge Swap by avoiding the transfer of assets two times. In this contract, you just “approve” the swap to spend on your behalf; hence there is only one transfer when the swap is matched.

There is a demurrage cost to holding gold. You may want to consider this as well when setting the price.

version 0.1 / md5: ddcefc45f807ee1bfb51076e07fee0c7

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