Interacting with Our NFTs
Ivan Montiel
Posted on August 6, 2023
Introduction
In this section, we are going to interact with AtomicAsssets via the Smart Contract we wrote in the last section. We will deploy the contract, and then use Bloks.io to view the contract, and show an example using Anchor to interact with the contract to purchase an NFT!
Deploying the Smart Contract
Let’s deploy our contract. Since we are using the same account name as our previous tutorials, this will overwrite the contract that is on the blockchain – but any old tables will continue to exist on the chain. This is important since it means even if we change the contract for our account, all of the data is immutable.
Let’s unlock our wallet:
cd /wax
cleos wallet open -n testwallet
cleos wallet unlock -n testwallet --password="$(cat ./secrets)"
No we will deploy our contract:
cleos -v -u https://testnet.wax.pink.gg set contract waxcourse123 ./babychicks/build/babychicks -p waxcourse123@active
This command may give you an error:
Reading WASM from /wax/babychicks/build/babychicks/guestbook.wasm...
Publishing contract...
Error 3080001: Account using more than allotted RAM usage
Error Details:
account waxcourse123 has insufficient ram; needs 81572 bytes has 9592 bytes
Stack Trace:
resource_limits.cpp:235 verify_account_ram_usage
In this case, we need to buy RAM for our account. This is a useful command to have bookmarked:
# Remember to change waxcourse123 to your account name
cleos -v -u https://testnet.wax.pink.gg \
system buyram waxcourse123 waxcourse123 "500" --kbytes \
-p waxcourse123@active
If everything succeeded, you will see similar output to the following:
In the next section, we will interact with our contract using the Bloks.io interface.
Setting Permissions
Before we interact with our contract, we need to set a permission setting for our account, otherwise we will see the following error when trying to call actions:
Provided keys, permissions, and delays do not satisfy declared authorizations
To remedy this, we need to run the following line after unlocking our wallet:
cleos --url="https://testnet.wax.pink.gg" set account permission waxcourse123 active --add-code
Now we can interact with out contract.
Interacting via Bloks.io
If we go to https://wax-test.bloks.io/account/waxcourse123 and then click on the Contract tab, we will be able to see the tables and actions our contract provides. Right now it leverages AtomicAssets to mint and handle the lifecycle of NFTs, so we won’t see any tables.
If we go to the Actions tab, we can see our airdropegg action that we defined.
You can type in your account name to mint an egg NFT. This will mint an egg just like we did during the Manually Minting NFTs section.
💡 Typically, this works on the production Wax Chain. Currently while writing, using the bloks.io interface was not working due to CORS issues.
Interacting via Anchor
An alternative way to work with the Smart Contract is through Anchor. Simply open Anchor, then go to Tools→Smart Contracts. Type your account name, in our case waxcourse123
.
Select the airdropegg
action and type in your account name:
You’ll see a Transaction submitted message when the transaction goes through:
Some common errors:
assertion failure with message: No collection with this name exists ()
You did not use the correct collection name from the one you originally created.
Purchasing an NFT
In the previous section, we used our admin functionality to mint an NFT egg. Most of our users will not be able to purchase an egg this way. Instead they will need to send WAX to our contract.
If you are using Anchor, you can transfer tokens to the wallet in order to mint an egg:
If you send the incorrect amount of WAX (say 200 instead of 2000), the contract will reject the transfer:
This helps users interact with our contract correctly without any need for manual refunds.
Dark Emblem
The mechanisms we used in this example Smart Contract and the way user’s can interact with the contract are all part of the Dark Emblem NFT Smart Contract. The Dark Emblem contract is deployed to the WAX mainnet, demonstrating how all of the above listed functionality can come together to create an interactive Smart Contract experience.
Conclusion
In this section, we went over how to purchase an NFT from our deployed Smart Contract. This is a huge step into creating awesome WAX blockchain experiences using NFTs. From here, we will be able to continue to build up new functionality for our BabyChick NFTs!
Next post: Using AtomicHub
E-book
Get this entire WAX tutorial as an e-book on Amazon.
Additional links
- Github: https://github.com/CapsuleCat/wax-nft-tutorial/tree/main/babychicks
- Photo by Brian McGowan on Unsplash
Posted on August 6, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.