Close
0%
0%

EthExchange

Open source, decentralized exchange on the Ethereum blockchain

Public Chat
Similar projects worth following
Ethereum has thousands of deployed ERC20 token contracts, existing on a decentralized blockchain.

But few exchanges are decentralized. EthX can solve this problem.Currently it can only be an exchange for tokens existing on the Ethereum blockchain, but I plan to expand that at some point. The contracts that allow trading exist on the blockchain, but I have no way to deploy the web interface in a decentralized way yet. Trading is between a token and Ethereum, later I will add a way to exchange for "old" currencies as well.

Currently EthExchange is on IPFS, you can take a peek here: https://ipfs.io/ipfs/QmeXq8wWyxajJpV1hHLxewYPqYwuczTSVsm9kWHxc3Ydkw

What does it do?

EthExchange provides an unregulated and decentralized exchange for Ethereum tokens.  There is a simple Dapp that gives the smart contracts an easy to use interface.

How does EthExchange work?

Each token either has functions to allow trading, or they have a 'latch' contract to add this functionality.  The Dapp interfaces with whichever contract enables trading, pulling data from the Ethereum network through MetaMask injected web3.

All of the code executes on the client, so private keys and other sensitive information never reaches the server.  There is no PHP, all of the 'working' code is in JavaScript.  I couldn't figure out Node.js so I am not using it.

EthExchange is on IPFS (more details here), a decentralized way to store files.  It can be accessed via your browser!

How can I take a look/try it out?

Currently EthExchange can be found at https://ipfs.io/ipfs/QmeXq8wWyxajJpV1hHLxewYPqYwuczTSVsm9kWHxc3Ydkw.  Eventually I will have a permanent link.

To use it you may need to disable your adblocker.  I have to disable mine.  Try with Adblock first if you have it, disable at your discretion.

You may also clone the repository here and run ./test.sh .  You will need MetaMask, python and SimpleHTTPServer.  It will open chrome if you have it, otherwise open any browser and go to http://localhost:8080/index.html .  From there you will be able to trade any coins I have listed.

  • Making EthX An Accessible Crypto Exchange

    Dylan Brophy06/19/2019 at 23:21 0 comments

    This exchange is useless if it cannot be accessed.

    Since this exchange aims to be entirely decentralized, there should not be a central server hosting EthExchange.  Then how are users going to be able to get the client side files for it?  Almost every webpage is hosted on a server.  Almost.

    I discovered this interesting protocol called IPFS (InterPlanetary File System) which allows files (and webpages to be hosted in a decentralized way, on a peer-to-peer network.  More info about IPFS on their site: https://ipfs.io/.  Anyway, I am hosting EthExchange there.  I will post more when it is properly hosted - it takes some time for a file to propagate across the network.

    When propagated, EthExchange will be available here.

    So that's super cool - I just made a decentralized Ethereum exchange!  It works too (although there isn't much there yet... YET)

    A programming "whoops": using parseInt instead of parseDouble

    I was trying to trade fractions of tokens on EthExchange, but my transactions indicated that I had requested to buy exactly zero tokens.  Long story short, I used the wrong parse function.  Whoops!  Fixed now, latest code is on the repo.

    [A quick note about EthX market cap indications:  they are wrong.  Another thing for me to fix.]

  • Latching to a token that isn't mine

    Dylan Brophy06/19/2019 at 01:43 0 comments

    At some point it would be nice to trade a token with actual value, right?  None of these tokens (as of right now) were created by me.  If you remember from the last log, the trading contract will need to 'latch' to an ERC20 token contract.

    So I decided to try to latch to the OmiseGo token on the Ethereum Mainnet.

    Did it work?  Nope.  I tried to place a sell order for the .16 OMG tokens I somehow have, but the transaction reverted.  So I found the OMG token source code and copied it into Remix to try to figure out why this revert was occuring.

    At first I thought that maybe my contract was reverting the transaction, misreading the 'allowance' values from the OMG contract, thinking it couldn't transfer.  I tried to debug but Remix wouldn't let me for some odd reason, very unhelpful.  Anyway, I started messing with the contract to try to find the issue.  It seems that my trading contract can indeed read the OMG contract values properly, but it's still reverting.  But only for sells - I can place a buy order.  Although, that order will never be executed, simply because sell orders are broken.  I have narrowed it down to these few lines:

    function placeSellOrder(uint tokens, uint64 price10000) public{
    	    require(ERC20(latched_contract).allowance(msg.sender, address(this))>=tokens);
    		
    		// handle fee and any extra funds
    		ERC20(latched_contract).transferFrom(msg.sender,address(this),tokens);
    		
    		// get info needed for trading
    	    uint left = tokens;
    ... function continues

    What's odd is that this works fine on my test token: LOL Coin (source: here), but breaks for OmiseGo.  It's as if OMG's smart contract is causing the revert in:

    ERC20(latched_contract).transferFrom(msg.sender,address(this),tokens);

     - but really I have no clue.

    If you're curious, OMG's source code is here, and my trading contract code can be found here.  You bet I'll keep looking into it.  If it doesn't work, then I'll test with the 300 or so Xenon tokens I also somehow have, although I think that coin is dead.

  • Order-Fulfilling Smart Contract

    Dylan Brophy06/18/2019 at 17:25 0 comments

    Market prices change when people trade at new prices.  People trade at new prices when orders at the old price are no longer fulfilled.

    Before my new smart contract, any token would be fixed to a certain price unless that price was manually changed.  My new contract allows the price to change by automatically matching buy and sell orders together.

    Let's say Alice places a buy order for 100 tokens at a price of 1.2 dollars, but no previous sell orders have been placed at or below this price.  The smart contract takes Alice's money, but lists her buy order.

    Now let's say Bob places a sell order for 250 tokens at a price of 1.05 dollars.  The smart contract now completes Alice's order, sending her 100 of Bob's sold tokens, and gives Bob his money.  But Bob is still selling 150 more tokens, so the contract takes these and lists a sell order.

    This is what all exchanges do every day, what the stock market does, etc.  But those systems are centralized.  This smart contract exists on the Ethereum blockchain, and it is decentralized.

    My current smart contract can be viewed on Etherscan here (along with source code):

    https://ropsten.etherscan.io/address/0x2400b7c684f1ddc738b7dcc4527c3b9af45cdac5#contracts

    The contract is not perfect (and this one has at least one minor bug), but as a proof of concept, it does seem to work.  Note that it is on the testnet - DO NOT SEND IT REAL ETHEREUM - you will be VERY SAD if you do.

    Next I need to weed out the bugs and add two more functions: placeBuyOrder() and placeSellOrder().  These functions will allow orders to be placed at any price.

  • Where I am so far

    Dylan Brophy06/15/2019 at 22:05 0 comments

    I've been working on this already for a week or two, so this log is to update on where this project is right now

    Essentially, trading is working, and the UI isn't beautiful but it is user-friendly.  Everything is still on the Ropsten Testnet.  All the tokens are using a fixed price system right now, so it wouldn't work for any non-stable tokens yet.

    Currently I am working on an Ethereum smart contract capable of processing orders, thus allowing the token price to fluctuate.

    Important thing: "latching contracts"

    This is a term I created for contracts that 'latch' to a certain token to enable trading.

    Trading protocols for smart contracts

    There are several trading protocols right now:

    • "legacy"
    • "Tr100"
    • "Tr100b"
    • "Tr100b-compat"


    "legacy" and "Tr100" are considered obsolete - not going over them.

    Tr100b and Tr100b-compat

    Contracts that use either of these protocols can:

    • tell you if a certain amount of tokens can be traded
    • tell you what the fee is, or zero if none
    • trade (obviously)
    • tell you what the cost of a buy or revenue of a sale would be
    • tell you the total token supply
    • tell you the token balance of an address

    The difference between them is that Tr100-compat is designed for latching contracts, and can also tell you which contract has been latched.

    That is the state of the project thus far!

View all 4 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates