Trade ERC20 tokens the safest way possible. Setting up BURSA trading environment.

bzz
3 min readFeb 9, 2018

--

BURSA DEX is a totally new concept in the world of Ethereum. It combines the idea of 0x protocol with on-chain order book. On the contrary to 0x, BURSA does not represent a JavaScript library or any other kind of off-chain solution. It IS just a smart contract on Ethereum network. It is verified and deployed under bursadex.eth ENS address. What does it do?

BURSA is a smart contract that atomically handles exchange operations on ERC20 tokens in Ethereum network. Unlike EtherDelta, it only supports trade pairs with ether. You cannot exchange one token to another without ether as intermediary. This provides a more convenient market data, a more adequate fee system and, that is particularly important, minimises gas costs. The idea behind BURSA is presented in my previous article.

BURSA smart contract can be interacted in a way similar to any other smart contract in Ethereum network.

The formal description of BURSA trading abi can be found here. You can trade from any Ethereum wallet that supports methods execution. In this tutorial, we will do that using Parity. To proceed with this tutorial, you need to have Parity installed, synced and connected to Ethereum network.

Choose “CONTRACTS” section. Press “+ WATCH” button.

Custom contract”, “-> NEXT”.

Network address: 0xd3e64580cb5b4d079514dcf2996dea6095a57e30

Contract name: BURSA

Contract abi:

[{“constant”:false,”inputs”:[{“name”:”amount”,”type”:”uint256"},{“name”:”token”,”type”:”address”},{“name”:”price_each”,”type”:”uint256"},{“name”:”bid_order_spot”,”type”:”uint256"}],”name”:”willbuy”,”outputs”:[{“name”:””,”type”:”bool”}],”payable”:true,”stateMutability”:”payable”,”type”:”function”},{“constant”:true,”inputs”:[],”name”:”updateAvailable”,”outputs”:[{“name”:””,”type”:”address”}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[],”name”:”name”,”outputs”:[{“name”:””,”type”:”string”}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”},{“name”:”min_trade_amount”,”type”:”uint256"}],”name”:”findBestBid”,”outputs”:[{“name”:”bid_order”,”type”:”uint256"},{“name”:”volume”,”type”:”uint256"},{“name”:”price”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[{“name”:”amount”,”type”:”uint256"}],”name”:”withdraw”,”outputs”:[],”payable”:false,”stateMutability”:”nonpayable”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”},{“name”:”user”,”type”:”address”}],”name”:”balanceApprovedForToken”,”outputs”:[{“name”:”amount”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”user”,”type”:”address”}],”name”:”balanceOf”,”outputs”:[{“name”:”balance”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”},{“name”:”ask_order”,”type”:”uint256"}],”name”:”willsellInfo”,”outputs”:[{“name”:”user”,”type”:”address”},{“name”:”price”,”type”:”uint256"},{“name”:”amount”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[{“name”:”amount”,”type”:”uint256"},{“name”:”token”,”type”:”address”},{“name”:”min_price_each”,”type”:”uint256"},{“name”:”bid_order”,”type”:”uint256"},{“name”:”frontend_refund”,”type”:”address”}],”name”:”sell”,”outputs”:[{“name”:””,”type”:”bool”}],”payable”:true,”stateMutability”:”payable”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”},{“name”:”min_trade_amount”,”type”:”uint256"}],”name”:”findBestAsk”,”outputs”:[{“name”:”ask_order”,”type”:”uint256"},{“name”:”volume”,”type”:”uint256"},{“name”:”price”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[{“name”:”amount”,”type”:”uint256"},{“name”:”token”,”type”:”address”},{“name”:”price_each”,”type”:”uint256"},{“name”:”ask_order_spot”,”type”:”uint256"}],”name”:”willsell”,”outputs”:[{“name”:””,”type”:”bool”}],”payable”:true,”stateMutability”:”payable”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”},{“name”:”bid_order”,”type”:”uint256"}],”name”:”willbuyInfo”,”outputs”:[{“name”:”user”,”type”:”address”},{“name”:”price”,”type”:”uint256"},{“name”:”amount”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[],”name”:”deposit”,”outputs”:[{“name”:””,”type”:”bool”}],”payable”:true,”stateMutability”:”payable”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”}],”name”:”willsellFindSpot”,”outputs”:[{“name”:”ask_order_spot”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”token”,”type”:”address”}],”name”:”willbuyFindSpot”,”outputs”:[{“name”:”bid_order_spot”,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[{“name”:”amount”,”type”:”uint256"},{“name”:”token”,”type”:”address”},{“name”:”max_price_each”,”type”:”uint256"},{“name”:”ask_order”,”type”:”uint256"},{“name”:”frontend_refund”,”type”:”address”}],”name”:”buy”,”outputs”:[{“name”:””,”type”:”bool”}],”payable”:true,”stateMutability”:”payable”,”type”:”function”},{“inputs”:[],”payable”:false,”stateMutability”:”nonpayable”,”type”:”constructor”},{“payable”:true,”stateMutability”:”payable”,”type”:”fallback”},{“anonymous”:false,”inputs”:[{“indexed”:false,”name”:”amount”,”type”:”uint256"},{“indexed”:false,”name”:”token”,”type”:”address”},{“indexed”:false,”name”:”price_each”,”type”:”uint256"},{“indexed”:false,”name”:”buyer”,”type”:”address”},{“indexed”:false,”name”:”seller”,”type”:”address”}],”name”:”Trade”,”type”:”event”}]

Press “+ADD CONTRACT

BURSA contract added to our contracts. Now we need to add the token that we want to trade. “CONTRACTS”, “+ WATCH”, “Token”. Add the token of your of your interest.

Click on the token contract you’ve just added.

Under the “CONTRACTS” icon, press “> EXECUTE” button.

Choose approve() function of the token.

Set BURSA contract address as _spender and enter amount of tokens you want to be available for trading. Parity has a slider on the right to let you omit entering additional 18 zeroes each time. You probably want to switch the slider before you start entering the amount. Leave Transaction value equal to zero. Press “POST TRANSACTION” button when finished.

You will be asked to accept the transaction and you’ll be able to change gas price and gas supply of this transaction. You can make sure that transaction successfully mined by checking allowance by calling allowance() on token contract or balanceApprovedForToken() on BURSA contract. Those methods are constant (aka view methods), which means they run locally and, therefore, do not consume gas.

Now, when you know how to run methods using Parity, you can just open BURSA contract and follow instructions on BURSA project github page. You can place orders, fill orders, cancel your own orders, deposit and withdraw ether. Enjoy the safe trading!

--

--