2. Deploying Smart Contract
Last updated
Last updated
You can use Remix Online IDE or use Truffle to deploy MyERC20
smart contract.
Please visit Klaytn Plugin for Remix and create a MyERC20
contract. The complete source code was given at Writing ERC-20 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.foundation/create or https://toolkit.klaytn.foundation/account/accountKeyLegacy.
Get some test KLAY from the faucet - https://baobab.wallet.klaytn.foundation/faucet
Let's deploy MyERC20.sol
with the deploy parameters of BAOBABTOKEN
, BAO
and 8
.
After deploying, you can invoke balanceOf
with your account, which was used to deploy the contract. You will find there are 10000000000000
tokens available in your account as below. Because you set decimal
as 8
when deploying the contract above, it minted a fixed number of 100000
tokens in the constructor, with one token having a decimal value of 10^8
. totalSupply
method will return the total supply of tokens minted which should be also 10000000000000
.
MyERC20
is now live !
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 contract.
Let's prepare truffle
and a smart contract MyERC20.sol
.
Now you will have following directory structures.
Now write MyERC20.sol
and locate it to contracts
directory.
Also edit 1_initial_migration.js
as below to deploys MyERC20
contract with initial parameters of BAOBABTOKEN
, BAO
and 8
. The token name is set to BAOBABTOKEN
and the token symbol to BAO
. Token has decimal value 10^8
. Note that when you query the totalSupply
of BAOBABTOKEN
for example, it returns 10^13
, not 10^5
, because solidity does not support floating point, the number of tokens always represented as a natural number in the smallest denomination.
You also have to edit truffle-config.js
as shown below to deploy a smart contract to Klaytn network. This is the same step described in Deploying a Smart Contract using Truffle.
Now you are all ready and can deploy MyERC20.sol
as below.
It shows that the transaction hash for deploying MyERC20
is 0x1571e80552dab1d67260e8914e06d9b16ccae16fb698c750f6a09aab12517bc1
and the address of MyERC20
is 0xc4c8257ED9B4eB6422fDe29B1eCe5Ce301e637e1
.
Now MyERC20
is live !