Swap Ether and ERC20 tokens on the Ethereum network. This is beta software so, please, use with caution.
If you found this helpful then you can buy me a beer at 0xA459552915C85d079b2EC8e28024314a538f3fd3.
- The buyer calls
create
to begin the Swap.
TokenSwap.create(token, tokenAmount, price, seller, buyer, [recipient])
token
is theaddress
of an ERC20-compatible token contracttokenAmount
is the amount of tokens to be soldprice
is the total price, in Wei, to be paid for the tokensseller
is the address of the token holderbuyer
is the address of the Ether holder (this address must send the payment to conclude the Swap)recipient
is an optional argument specifying an address to receive the tokens; if norecipient
is specified thenbuyer
is used
- The seller approves the TokenSwap contract to spend
tokenAmount
tokens, using the ERC20approve
function. - The buyer calls
conclude
withprice
Wei.
If the tokens have not been approved then the call will fail. If the tokens have been, and the value of the call is sufficient, the tokens will be sent to the recipient (or buyer, if none is specified) and the Ether to the seller.
An additional cancel
function has also been provided. The buyer
, seller
and recipient
are all able to cancel a Swap at any time before it is concluded. Any tokens that have been approved will be refunded.
- Install
truffle
andopenzeppelin-solidity
by runningnpm i
. - Compile the contracts using
truffle compile
. - Run the test by installing and launching ganache, then running
truffle test
.
MIT © Luke Mitchell