This repository contains the solidity code of a decentralized NFToken Exchange, this is a smart contract on Ethereum local network using Truffle Framework.
If you want use this on ropsten testnet, we also have deployed contract, please check deployed contract.
I develop a DApp where the users can exchange NFToken like cryptoKitties, etheremon..., as long as they meet the Erc721 standard.
Cause it's not easy to get free erc721 token on ropsten testnet, I create two Erc721 contract (NFToken, NFToken2) in this repository so that users can easy to get token and test exchange function.
there already have websites on ropsten network you can trade Erc721 token i created and get free Erc721 token, please check websites.
It still in early development phrase, I can't guarantee that contract has no security risks.
- Websites
- Install
- Test
- Send NFToken to Exchange
- Order and MatchOrder
- Exchange NFToken
- Deployed Contract
- Get Erc721 token on testnet
- Erc721 sample project
NFToken Swap is a Dapp can trade two Erc721 token, CryptoCat and CryptoBot. and you can get free CryptoCat and CryptoBot at NFToken Faucet.
Dapp was developed with truffle framework, you can read truffle's document to know how to test and deploy.
If you need to run a local blockchain, You need to pay attention to configure and run Ganache.
You can understand the flow of the entire program by testing and read it code.
truffle test
First, if you want to exchange NFToken with others, you must transfer your NFToken to Exchange contract, but please don't directly send your NFToken.
You must call setApprovalForAll
on your NFToken Contract and set true to Exchange contract address, and then call receiveErc721Token
on Exchange Contract. Exchange Contract will instead you to transfer NFToken to itself and record necessary information so you can exchange token success.
Don't worried about your NFToken lost, if you want get your NFToken back,just call sendBackToken
and your NFToken will back to your original address.
Order or matchorder is a hash can mapping to one NFToken's inforamtion.
If you want to exchange your NFToken on Exchange Contract, you must call createOrder
to create an order first. it will create a hash and you can use it to search information(owner, NFToken contract address, NFToken id) by call getHashOrderObj
.
If other people like your NFToken and want to provide their NFToken to exchange with you, they can call createMatchOrder
and fill the hash in the parameters to show that they want to exchange with you.
You just checked by getOrderMatchOrders
that will return an array include all hash that want to exchange with you.
If you are an order's owner, find one matchorder in your order's mathorder array and The NFToken it represents you want to exchange, you can call exchangeToken
and fill in the parameters of both hashes.
As long as matchorder is effective, the transaction happens immediately, The NFTokens will be sent to the corresponding address.
There already have deployed contract on Ropsten testnet and Mainnet, you can use etherscan Write Contract UI interface to interact with contract.
you can call generateToken()
on NFToken or NFToken2 contract and then you can get free erc721 token
to test.
NFToken and NFToken2 is duplicate and slightly modified from this link