2. Deploying Smart Contract
You can use Klaytn IDE or use truffle to deploy above MyERC721Card
smart contract.
2.1 Deploying smart contract using Klaytn IDE
Please visit the Klaytn IDE website and create a
MyERC721Card
contract. The complete source code was given at Writing ERC-721 Smart Contract.Prepare your account which will be used to deploy the contract.
If you do not have an account yet, create one at https://baobab.wallet.klaytn.com/create
Get some test KLAY from the faucet - https://baobab.wallet.klaytn.com/faucet
Let's deploy
MyERC721Card.sol
as below.
Now MyERC721Card
is live! You can mint and transfer cards which are ERC-721 compatible non-fungible tokens.
Let's mint two cards, i.e. King
and Queen
cards, for account 0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410
as below.
Now we have minted two cards and let's check the status of these MyERC721Card
non-fungible token.
balanceOf
shows that account0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410
has two cards.cards
with parameter1
shows thatMyERC721Card
with token ID1
is aQueen
of level 1.ownerOf
with parameter0
shows that owner ofMyERC721Card
with token ID0
is0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410
.
2.2 Deploying smart contract using truffle
You should have installed node.js in your environment. Please take a look at Installing Node.js via package manager to install node.js using package manager in various environment.
Now you have installed truffle and caver-js which are required to deploy smart contracts.
Let's prepare truffle
and a smart contract MyERC721Card.sol
.
Now you will have following directory structures.
After write MyERC721Card.sol
and locate it to contracts
directory, directory structure will be as follows.
Now you will have following directory structures.
Also, edit 1_initial_migration.js
as shown below to deploy the MyERC721Card
contract.
You also have to configure truffle-config.js
to deploy the smart contract to Klaytn network. This is the same step described at Deploying a Smart Contract using Truffle
Now you are all ready, let's deploy MyERC721Card.sol
using the following command.
The console output shows that the transaction hash for deploying MyERC721Card
is 0x1571e80552dab1d67260e8914e06d9b16ccae16fb698c750f6a09aab12517bc1
and the address of MyERC721Card
is 0xc3d282926871c505f334d0f2c85ad52758347831
.
Last updated