
How to implement a `mint` function in your NFT contract?
Here’s the simplest NFT contract:import '@openzeppelin/contracts/token/ERC721/ERC721.sol'; contract SimplestNFT is ERC721 { function mint(uint256 tokenId) external { _safeMint(msg.sender, tokenId); } } It delegates the heavy lifting to the base contract implementation (in this case, OpenZeppelin). _safeMint is responsible for matching the ERC721 spec: it does some checks, stores data about ownership, emits events and calls callbacks. But you don’t want to allow anyone to call this function wi...

NFT project story: building and open sourcing Rings for Loot
What does it take to build an NFT project? How does it work end-to-end, from an idea to collectibles in the user's wallet? How much does it cost?Rings (for Loot)Rings (for Loot) is the first and largest 3D interpretation of an entire category in Loot. Adventurers, builders, and artists are encouraged to reference Rings (for Loot) to further expand on the imagination of Loot. The Rings project is Jeremy Goldberg's idea. Jeremy made all the stunning artwork, 0xHab helped shape tokenom...

BasePaint
“This is the most fun I had onchain in a long time” — creators and users of BasePaint. Let me tell you a story about building BasePaint, a collaborative pixel art project that is unlike what you typically see in the crypto space. I’ve been writing this post for the last 100 days and did my best to make sure it’s not too boring. Buckle up and consider minting!BasePaintInspired by /r/Place & The Million Dollar HomepageI remember the first time I saw the source code for an NFT smart contract. My...
❄️

How to implement a `mint` function in your NFT contract?
Here’s the simplest NFT contract:import '@openzeppelin/contracts/token/ERC721/ERC721.sol'; contract SimplestNFT is ERC721 { function mint(uint256 tokenId) external { _safeMint(msg.sender, tokenId); } } It delegates the heavy lifting to the base contract implementation (in this case, OpenZeppelin). _safeMint is responsible for matching the ERC721 spec: it does some checks, stores data about ownership, emits events and calls callbacks. But you don’t want to allow anyone to call this function wi...

NFT project story: building and open sourcing Rings for Loot
What does it take to build an NFT project? How does it work end-to-end, from an idea to collectibles in the user's wallet? How much does it cost?Rings (for Loot)Rings (for Loot) is the first and largest 3D interpretation of an entire category in Loot. Adventurers, builders, and artists are encouraged to reference Rings (for Loot) to further expand on the imagination of Loot. The Rings project is Jeremy Goldberg's idea. Jeremy made all the stunning artwork, 0xHab helped shape tokenom...

BasePaint
“This is the most fun I had onchain in a long time” — creators and users of BasePaint. Let me tell you a story about building BasePaint, a collaborative pixel art project that is unlike what you typically see in the crypto space. I’ve been writing this post for the last 100 days and did my best to make sure it’s not too boring. Buckle up and consider minting!BasePaintInspired by /r/Place & The Million Dollar HomepageI remember the first time I saw the source code for an NFT smart contract. My...
❄️

Subscribe to w1nt3r.eth

Subscribe to w1nt3r.eth
Share Dialog
Share Dialog
>8.2K subscribers
>8.2K subscribers


You mint or buy things, and they show up in your wallet — you see them in MetaMask, Rainbow, whatever you have. "Wallet" is a useful concept when explaining web3 to people.
But if you look under the hood, it's not at all how it works.
Your wallet is just an address: a 160-bit number that looks like 0x123a…c8f9. It doesn't really store anything.
The things you have "in your wallet" are actually defined by the contracts.
Each NFT or token you interact with is a contract — a piece of code on Ethereum blockchain. To be considered an NFT or a token, the code has to implement a bunch of standard functions described in the corresponding standard (e.g. ERC721 or ERC20).
For example, ERC20 token standard has a function called balanceOf. The contract baking the token is free to implement this method in any way it wants. Most methods store the balance inside the contract storage as a map from address to balance. Some tokens implement inflationary balance, where the balance reported is your original balance multiplied by the amount of time you held it for.
The wallet software just calls these functions and shows the results in the UI. So does OpenSea, UniSwap and any other web3 platform.
Try it yourself! Here's contract address for WETH token. You can open its Contract tab on Etherscan, find the balanceOf method and call it with any Ethereum wallet address:

You can also look at WETH's source code and see that indeed it stores the balance inside contract storage (and not in your wallet)

How do wallets know which contracts to call?
The simplest way to do that would be to ask the user to manually add every coin or NFT they have. It’s not very popular because it’s a terrible user experience and goes against the “wallet” concept.
Alternatively, the wallet software could call balanceOf on every contract ever deployed to Ethereum. That’s very costly and slow. This could also show millions of spammy tokens.
So “show me the coins I have in my wallet” is actually a non-trivial problem that is not solved by Ethereum out-of-the-box. A lot of third-party services provide a layer on top of Ethereum that aggregates tokens and NFTs “held” by a given wallet address (e.g. zapper.fi)

You mint or buy things, and they show up in your wallet — you see them in MetaMask, Rainbow, whatever you have. "Wallet" is a useful concept when explaining web3 to people.
But if you look under the hood, it's not at all how it works.
Your wallet is just an address: a 160-bit number that looks like 0x123a…c8f9. It doesn't really store anything.
The things you have "in your wallet" are actually defined by the contracts.
Each NFT or token you interact with is a contract — a piece of code on Ethereum blockchain. To be considered an NFT or a token, the code has to implement a bunch of standard functions described in the corresponding standard (e.g. ERC721 or ERC20).
For example, ERC20 token standard has a function called balanceOf. The contract baking the token is free to implement this method in any way it wants. Most methods store the balance inside the contract storage as a map from address to balance. Some tokens implement inflationary balance, where the balance reported is your original balance multiplied by the amount of time you held it for.
The wallet software just calls these functions and shows the results in the UI. So does OpenSea, UniSwap and any other web3 platform.
Try it yourself! Here's contract address for WETH token. You can open its Contract tab on Etherscan, find the balanceOf method and call it with any Ethereum wallet address:

You can also look at WETH's source code and see that indeed it stores the balance inside contract storage (and not in your wallet)

How do wallets know which contracts to call?
The simplest way to do that would be to ask the user to manually add every coin or NFT they have. It’s not very popular because it’s a terrible user experience and goes against the “wallet” concept.
Alternatively, the wallet software could call balanceOf on every contract ever deployed to Ethereum. That’s very costly and slow. This could also show millions of spammy tokens.
So “show me the coins I have in my wallet” is actually a non-trivial problem that is not solved by Ethereum out-of-the-box. A lot of third-party services provide a layer on top of Ethereum that aggregates tokens and NFTs “held” by a given wallet address (e.g. zapper.fi)

No activity yet