I'm trying to allow NFT holders to sell their tokens by listing prices (ETH) and allow others to buy those listed tokens.

I used openzeppelin and succesfully implemented and tested my token creation. Now, if I want that exchange to be happened, how do I further implement? I created another contract btw to begin with.

import "openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";

contract MyTokenSale {

 ERC721Token public token;

 constructor(address _tokenAddress) public {
    token = ERC721Token(_tokenAddress);

Any examples or code snippets would be greatly appreciated.


You can checkout the 0xcert framework that is made for managing erc721 tokens. You already have a build in exchange, erc721 creation, transfer etc and there are tutorials available for everything. Plus you don't need to know anything about solidity.

If you want to do it yourself you should checkout their smart contracts for exchange on which you can base your token selling.

Otherwise the basic concept if you want to sell a NFT for ETH would be.

  • Create NFT (make sure only you can create it)
  • Set price in ETH for specific NFT (for its id)
  • Create a payable function that accepts id as parameter
  • Check if the id is really for sale
  • Check if the amount of eth sent is enough
  • remove from you selling list (you have to do thins before doing any transfers to avoid a reentry attack)
  • transfer the token
  • transfer eth to your wallet

You could list your tokens for sale on OpenSea without creating a sale contract.

To create your own token sale contract you could look at OpenZeppelin crowdsale contracts for inspiration, though these are for ERC20 (fungible, rather than ERC721 non-fungible). https://docs.openzeppelin.org/v2.3.0/crowdsales

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.