Klaytn Docs
Search…
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

ERC721-1-deploy
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.
ERC721-2-mint-king
ERC721-3-mint-queen
Now we have minted two cards and let's check the status of these MyERC721Card non-fungible token.
ERC721-4-cards-status
  • balanceOf shows that account 0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410 has two cards.
  • cards with parameter 1 shows that MyERC721Card with token ID 1 is a Queen of level 1.
  • ownerOf with parameter 0 shows that owner of MyERC721Card with token ID 0 is 0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410.

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.
1
$ mkdir klaytn
2
$ cd klaytn
3
$ npm init # initialize npm at the erc20token directory
4
$ npm install [email protected]
5
$ npm install [email protected] # installing caver-js
6
$ ln -s node_modules/truffle/build/cli.bundled.js truffle
7
$ export PATH=`pwd`:$PATH
Copied!
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.
1
$ mkdir myerc721
2
$ cd myerc721
3
$ truffle init
Copied!
Now you will have following directory structures.
1
.
2
├── contracts
3
│ ├── Migrations.sol
4
├── migrations
5
│ └── 1_initial_migration.js
6
└── truffle-config.js
Copied!
After write MyERC721Card.sol and locate it to contracts directory, directory structure will be as follows.
Now you will have following directory structures.
1
.
2
├── contracts
3
│ ├── Migrations.sol
4
│ └── MyERC721Card.sol
5
├── migrations
6
│ └── 1_initial_migration.js
7
└── truffle-config.js
Copied!
Also, edit 1_initial_migration.js as shown below to deploy the MyERC721Card contract.
1
const Migrations = artifacts.require("./Migrations.sol");
2
const MyERC721Card = artifacts.require("./MyERC721Card.sol");
3
module.exports = function(deployer) {
4
deployer.deploy(Migrations);
5
deployer.deploy(MyERC721Card)
6
};
Copied!
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
1
// truffle-config.js
2
module.exports = {
3
networks: {
4
baobab: {
5
host: '127.0.0.1',
6
port: 8551,
7
from: '0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd', // enter your account address
8
network_id: '1001', // Baobab network id
9
gas: 20000000, // transaction gas limit
10
gasPrice: 250000000000, // gasPrice of Baobab is 250 ston
11
},
12
},
13
compilers: {
14
solc: {
15
version: "0.5.12" // Specify compiler's version to 0.5.12
16
}
17
}
18
};
Copied!
Now you are all ready, let's deploy MyERC721Card.sol using the following command.
1
$ truffle deploy --network baobab --reset
2
Compiling ./contracts/MyERC721Card.sol...
3
Writing artifacts to ./build/contracts
4
5
Using network 'baobab'.
6
7
Running migration: 1_initial_migration.js
8
Replacing Migrations...
9
... 0x5a947f076f4570dff8ff18b1ae3557e27dd69c92ce38a3c97fad8f5355914066
10
Migrations: 0x0d737e9865e5fc4c1ff53744fd2c13c52a44b9bc
11
Deploying MyERC721Card...
12
... 0x1571e80552dab1d67260e8914e06d9b16ccae16fb698c750f6a09aab12517bc1
13
MyERC721Card: 0xc3d282926871c505f334d0f2c85ad52758347831
14
Saving successful migration to network...
15
... 0x5b984b3f79c425d80470a96d5badb857fc05e7f31d94423044ae3119c639aa77
16
Saving artifacts...
Copied!
The console output shows that the transaction hash for deploying MyERC721Card is 0x1571e80552dab1d67260e8914e06d9b16ccae16fb698c750f6a09aab12517bc1 and the address of MyERC721Card is 0xc3d282926871c505f334d0f2c85ad52758347831.