These are steps for creating and deploying a smart contract and minting assets. I followed these guides for the most part to the letter. Some exceptions:
- I used my own NFT name,
akadenianft
and symbolAKADENIA
. - I used
yarn
instead of NPM. - I copied the presets from the node_modules directory to my project directory per the documented procedure, but I didn't like that for obvious reasons. I had to diff the two directories later to see what changes the compile step applied to
build/contracts
. It might make it easier to see what is going on if the preset were imported: https://docs.openzeppelin.com/contracts/3.x/api/presets#ERC721PresetMinterPauserAutoId - I used a moralis speedy node instead of the URL in the example truffle-config.json (but only after I deployed the contract and minted NFTs). The moralis speedy node seems to have better availability.
- To interact with the contract on testnet I used
truffle console --network testnet
Project setup and initial development
Follow the procedure described in at the following URL:
https://docs.binance.org/smart-chain/developer/ERC721.html
My 2_deploy.js
seemed to have a bug and I didn't know what the third argument to deploy
was so I wound up making a 3_deploy.js
that looks like this:
// migrations/2_deploy.js
// SPDX-License-Identifier: MIT
const ERC721PresetMinterPauserAutoId = artifacts.require(
"ERC721PresetMinterPauserAutoId"
);
module.exports = function(deployer) {
deployer.deploy(
ERC721PresetMinterPauserAutoId,
"akadenianft",
"AKADENIA",
"http://my-json-server.typicode.com/huangsuyu/nft/tokens/"
);
};
The arguments to deploy
are as follows:
is the contract object, the second is the name of the smart contract,
- contract object (
ERC721PresetMinterPauserAutoId
) - Smart contract name (
akadenianft
) - Smart contract symbol (
AKADENIA
) - Base URI for tokens (This will have the token ID appended when calling
tokenURI
(example:http://my-json-server.typicode.com/huangsuyu/nft/tokens/1
)
Without the trailing /
the token URIs were invalid; for example, ending in tokens1
instead of tokens/1
.
After I deployed the smart contract to the local network using truffle develop
I had to switch over to the following guide to deploy to BSC testnet:
https://docs.binance.org/smart-chain/developer/deploy/truffle.html
To complete this procedure you will first need to setup a wallet with an account connected to BSC testnet. I can't remember how that was setup. I used MetaMask. When you create your account you will be given a “Secret Recovery Phrase,” be sure to store that somewhere safe. This is also referred to as mnemonic
in the procedure. I just created a plain text .secret
file with the recovery phrase as the content.
.secret
will be imported into truffle-config.json
you should just be able to uncomment those lines of code. You will also need to add a network for bsc testnet. I called it testnet
just like the documentation. I changed to node URL to the one that can be retrieved from https://admin.moralis.io/speedyNodes
. It seems to be more reliable.
Last thing, use truffle console --network testnet
to mint NFTs instead of truffle develop
.