[Astar] Develop NFT with ink!
Introduction
I introduced how to use Openbrush before. However, it was simply a matter of trying out the samples that Openbrush created.
Last time, I introduced PSP22, which is ERC20 in Ethereum. This time, I will introduce PSP34 which is ERC721.
By the way, PSP stands for “Polkadot Standards Proposals”. Please check this URL for details.
Table Of Contents
- Check my environment of rust.
- Check the PSP34 specs on the Openbrush page.
- Explain the sample code that I have implemented.
- Execute and check operation.
1. Check my environment of rust.
% rustup show
Default host: x86_64-apple-darwin
rustup home: /Users/shin.takahashi/.rustupinstalled toolchains
--------------------stable-x86_64-apple-darwin
nightly-2020-04-06-x86_64-apple-darwin
nightly-2022-03-14-x86_64-apple-darwin
nightly-x86_64-apple-darwin
1.51.0-x86_64-apple-darwin
1.61.0-x86_64-apple-darwin (default)active toolchain
----------------1.61.0-x86_64-apple-darwin (default)
rustc 1.61.0 (fe5b13d68 2022-05-18)
notice: I tried updating rust to the latest version once, but please note that the Openbrush library can no longer be compiled.
When I returned to the version on the substrate official page, I was able to compile successfully.
2. Check the PSP34 specs on the Openbrush page.
If you look at the implementation of PSP34 in Openbrush, you can see that the standard NFT implementation is done.
In addition to this standard implementation, extended implementations such as mintable and burnable are prepared.
3. Explain the sample code that I have implemented.
This time, I implemented an extension for PSP34 with the following specifications.
- (1) Save “name”, “symbol”, “base_uri” as metadata.
- (2) Assuming a token sale, require users to pay a certain amount of native tokens at mint.
To achieve (1), I used the “metadata” extension provided by Openbrush.
Follow the example of PSP34 and implement as follows.
To achieve (2), I first tried to use the “mintable” extension. However, the standard mint function cannot request payment, so I implemented the function myself.
The following github repository has the entire source, so please refer to it.
notice: This repository is part of my DAO dApp under development and is subject to change without notice.
4. Execute and check operation.
If you have not downloaded the astar network node, please download the binary file from the following site.
Since we are implementing a debug statement this time, we will start in the mode where the log is output to the standard output of the node.
./astar-collator --dev -lruntime=debug
Once the node has finished booting, access the “polkadot/substrate portal” and connect to your local node.
Let’s deploy the compiled contract.
Next, try minting twice. Please also check that an error will occur if ASTL is missing.
In order to confirm that the transaction is working correctly, you can confirm that it was executed correctly by confirming that it was issued with the “owner_of” function.
Next Step
I’m very interested in “Openbrush” and “Swanky” as ink! development tool projects. I will continue to monitor the progress of the project.
One of the recent notable news of Astar Network is “XVM”, a technology that can mutually call EVM and WASM. Details on how to use it have not yet been made public, but I am paying close attention to it. As soon as it becomes available, I would like to make an article about it.
The reason why I’m focusing on blockchain is because I believe that people and communities who could not do anything until now can use this infrastructure to help make society better. For that reason, I’m thinking of creating a DAO tool that anyone can use at a low cost.
It’s not affiliated with Astar Network, but if you’re interested, check it out.
About Astar
Astar Network — The Future of Smart Contracts for Multichain.
Astar Network supports the building of dApps with EVM and WASM smart contracts and offers developers true interoperability, with cross-consensus messaging (XCM). We are made by developers and for developers. Astar’s unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build.
Astar’s vibrant ecosystem has become Polkadot’s leading Parachain globally, supported by all major exchanges and tier 1 VCs. Astar offers the flexibility of all Ethereum and WASM toolings for developers to start building their dApps. To accelerate growth on Polkadot and Kusama Networks, Astar SpaceLabs offers an Incubation Hub for top TVL dApps.