The smart contract used in this deployment is already precompiled in Cryptum. For more details, you can see the source code here ./contracts/TokenERC721.sol and ./contracts/TokenERC1155.sol.
As you may have heard, NFT stands for Non-Fungible Token. This means that, by nature, all tokens that follow this pattern will be inherently different from each other. This ensures, among all the regular blockchain benefits like immutability and decentralization, verifiable uniqueness. In this guide, we will learn how to create (mint) an NFT on the Binance Smart Chain blockchain using our SDK.
Currently, Cryptum supports the following EVM blockchains: Celo, Ethereum, BSC, Avalanche (C-Chain), Polygon, Stratus and Hyperledger Besu. This tutorial works with any of these protocols!
But first, let's explain what a Collection is. If you think of NFTs as trading cards, the collection would be the set the card belongs to. Before minting your NFT, you must first create a collection. In more technical terms, Collection is the smart contract that manages all the minting, burning and transfers of all your tokens.
Creating NFTs Programmatically with Cryptum SDK
Step 1
The first prerequisite you will need is the creation of an account and a Project (API Key) on Cryptum Dashboard.
To do so, access our Dashboardand create a DEV-type Project.
Step 2
With a valid Cryptum API Key, you can then instantiate the SDK as follows:
Then you must instantiate the wallet that will be used to create the NFTs:
constwallet=awaitsdk.wallet.generateWallet({ protocol:'BSC', mnemonic:'lorem ipsum dolor sit amet consectetur adipiscing .....', derivation: { account:0, address:0 }})
Make sure the wallet has sufficient funds to pay for the transactions.
Step 4
Call the sdk.nft.create function passing your wallet, the token type can be either ERC721 or ERC1155, name of the collection, symbol, and targeted protocol:
The function returns the transaction hash of the smart contract deployment to the blockchain. To use this new token you need its address which you can retrive it from like this:
This function will only work if the NFT was created using the function above sdk.nft.create
Once the transaction has been sent and processed by the blockchain, we can prepare another transaction to mint an NFT into the collection we just created in the previous step. We'll populate the contractAddress attribute with the contract that was recently deployed in the previous step. Lastly, we'll pass with the destination, tokenId, URI and the amount:
The amount should be 1 or null if this token type is ERC721.