Best practices when handing payments ๐ธ in NFT contracts #solidity โ
Pull, don't push.
* If you forward ether payments from your mint function, it makes minting more expensive.
* If your contract gets some Ether without triggering the mint function, these funds will be lost forever.
Instead, make a function that transfers you the full balance.
Note that the withdrawAll function isn't marked as onlyOwner. Anyone can call it. This lets you set up automation (e.g. via Infura or OZ defender) that doesn't depend on your private keys.
While you are here, it's also a good idea to include a function that does the same but for any ERC20 token.
There are plenty of ways your contract can get these, and it would be unfortunate to lose thousands of dollars by not implementing this simple function.
Always check for the exact payment value.
I used msg.value > X ether in my first NFT contract, and it caused a lot of headaches. Some users minted from Etherscan's UI and miscalculated the proper value, and then chased me asking for a refund (which I did). Not fun.
Royalties (IERC2981) is a good idea, but there are some gotchas. The payment token can be anything, so make sure the royalties receiver is either the owner or the contract has a way to extract ERC20s. Here's an example where funds got locked forever
Here's how we are implementing royalties support for @watchfacesworld. Note that we can upgrade the royaltyInfo in the future by supplying a new implementation. This is cool because we could offer our holders some royalties (no promises ๐ ), without locking the logic now.
Last 2๐ธ tips for now:
1) Use a shared @gnosisSafe for your team (ideally with N/M signatures requirement). It'd really suck to lose your hard earnings in case someone is compromised.
Someone on Discord asked why we choose to go with Ethereum mainnet for @watchfacesworld NFT instead of an L2. Here's our thinking process on thisโฆ
We want to make Watchfaces last forever. The kind of antique rare physical timepieces that represent the times they were crafted in.
It's fully on-chain and will be alive for as long as Ethereum is alive. No external dependencies, no servers, no IPFS.
We don't have any plans to have active on-chain utility (like some games or art projects) that would require many transactions and would benefit from being on L2. Thus, the main benefit (as I see it) of L2 would be a cheaper deployment cost. Currently, we estimate to spend 1.5ฮโฆ
Should you build a minting pass for your upcoming NFT project? I definitely recommend you do! Itโs actually super simple, and Iโve learned a lot when building one for @watchfacesworld.
Here are 3 principles I want to share, a few bonus tips, and a code sample โ
First, what is a minting pass?
It's a simple NFT token that gives the holder access to private minting. They became very popular lately, esp. for high-profile projects to help alleviate gas wars and frustrations.
But minting passes can be useful for every upcoming NFT project
Principle 1: Minting pass is a relationship.
When someone says your project is cool, it's inspiring, but means very little.
When someone buys a pass for your project, it's a strong signal that they are interested. Ask them how they found you, give them special perks.