Bored Ape Yacht Club: Smart Contract Breakdown | by Nazar Ilamanov | Mar, 2022

Explaining its functionality by grouping lines of code

  • What’s the utility of an Ape? What do you really get if you buy one?
  • How do they actually implement their promise land of merch, exclusive access, etc?
  • How is access control implemented?
  • How are secondary payments (royalties) implemented?
  • The market dynamics during the NFT sale
  • How much founders of BAYC earned
  • A silly bug of BAYC and how other NFTs blindly copied it
  • ERC721 — the NFT standard
  • BAYC contract source code
  • What happened after contract deployment
  • tokenURI — the path to the token metadata (like the image, qualities of the token, etc)
  • tokenByIndex — returns tokenId of the token at the specified index
  • tokenOfOwnerByIndex — same as tokenByIndex but for the specified owner

How BAYC implements ERC721

  • They use mappings to manage ownership of tokens:
  • Here is how ownership is transferred(just reassign values ​​in the mapping):
  • Mappings are also used to manage approvals and operators:
  • Although not part of the standard, Openzeppelin adds mint/burn functions for adding/removing tokens:
“burn” function is just a mirror image of “mint”
  • Provenance — it’s supposed to be a unique signature for the entire NFT collection (change even one image and signature won’t match). The BAYC page on provenance explains how this signature is generated:
  • Unfortunately, provenance is not constant and can be changed at any time by the owner.
  • The other 2 unexplained things: baseUri and startingIndex will be explained later in the article.
  • Wasting gas — BAYC computes reveal timestamp in the constructor. This can be avoided by just passing in the already computed value.
  • Even though REVEAL_TIMESTAMP is spelled with uppercase, it’s not constant — can be changed by the owner at any time. Same for BAYC_PROVENANCE.
  • Apes can be reserved by the owner in unlimited quantity👌.

A silly mistake by BAYC and how other NFTs blindly copied it

30 Apes were reserved

What is baseUri?

Back to the history of transactions

  • started the sale
  • then changed their mind
  • and then 16 hours later, started it again
  • and the minting process started
  • there are a lot of mintApe txns
  • then you start seeing transferFrom and setApproval txns
  • then, 4 days After the sale started, we see the first withdrawal of 14 ETH (175 Apes at 0.08 ETH/Ape) by the BAYC team.

Closing thoughts

Leave a Comment