Hackatom V — NFT Marketplace Smart Contract

From October 16th till October 31st, Tendermint hosted their fifth Hackatom which we took as a great opportunity to flex our creative muscles and learn something in the process. Our team has been working very hard (and also very late) on stitching our project together and we’re very proud of what we achieved. With that being said, we’d like to share our Hackatom V experience with you in this article, what we’ve accomplished, hurdles we had to overcome and what we’ve learned at the end of the day.

The Blockscape Team

Cosmons Artwork

Our Project Idea: A Generic NFT Marketplace

We pictured a smart contract that would allow users to sell, buy, trade and auction CW721 tokens in exchange for CW20 tokens in one central place for maximum visibility. The key feature was to make our marketplace generic, so as to allow any CW721 token to be sold for any CW20 token with plans to add support for cross-chain interoperability, allowing us to introduce other native tokens, like Atoms. As a cherry on top of our idea, we also wanted to create a fun Pokémon-inspired NFT contracted called “Cosmons” which would allow users to battle other Cosmons with a nice little frontend in addition to selling, buying, trading and auctioning them.

Alright, let’s summarize, what our plans were thus far:

  • A generic NFT marketplace smart contract
    - putting any CW721 token up for sale for any amount of any CW20 token
    - buying CW721 tokens with CW20 tokens
    - trading any CW721 token with any other CW721 token
    - putting any CW721 token up for auction with a time limit and a bidding function
  • A custom CW721 contract called “Cosmons”
    - battling other Cosmons
    - provide a neat little frontend

Challenges: Rust Strikes Back

What We Had to Drop

First thing we realized was that we wouldn’t be able to implement all the marketplace functionality we envisioned. We then settled for a cut-down version that would allow users to sell tokens, buy them off of a global list of offerings and withdraw offerings.

Second thing we had to drop was our custom Cosmons images, simply due to the fact that we ran out of time adding those to the project. We did, however, add them after the deadline because it’d be a shame if people wouldn’t be able to see our original artwork. Since we managed to finish the marketplace contract just in time (literally), we haven’t been able to finish the frontend interface for it either. That was also added after the deadline.

The Marketplace Contract Under the Hood

Contracts involved & message flow

The only time you have to interact with the marketplace itself is either for querying the current list of offerings or when you want to withdraw an offering you previously made. In order to trigger a sale or purchase of a token, the token-specific contract needs to be talked to.

Both the CW20 and the CW721 standards specify a “send” / “send_nft” message which can be executed on the contract. These are used to ‘transfer’ tokens to other contracts which must implement a “receive” / “receive_nft” message. The tokens are not really transferred, merely the ownership is changed to the recipient contract which is also notified about the transfer via the “receive” message.

So, all in all, our marketplace is compatible with any tokens adhering to the CW721 and CW20 standards right out of the box. Just build, deploy, instantiate and you are ready to go.

Our Achievements

The current state of our marketplace contract is already pretty useful and has some great potential in terms of extending its functionality and providing support for cross-chain interoperability. It provides a great foundation for our future implementation plans and we’re definitely going to tackle them.

Special Thanks

If you’d like to check out the contract for yourself, check out our GitHub!

Validator operator in 15+ PoS blockchains. Visit us at www.blockscape.network.