5. Deploy Contract
Last updated
Last updated
Get some testnet KLAY to deploy contract
Truffle configuration
Deploy setup (select contract which you want to deploy)
Deploy
To deploy contract, we need some KLAY in your account to pay for gas price. You can get 150 KLAY via Klaytn Wallet in the testnet. 1. Create your Klaytn account at Baobab Klaytn Wallet -> PRIVATE KEY
will be used in truffle configuration. So copy it down somewhere 2. After creating your Klaytn account, run faucet to receive 5 Baobab testnet KLAY in Baobab Klaytn Faucet
truffle-config.js
is a configuration file including deployment configuration. We are going to deploy our contract using Private key
we've just created in the previous step. Paste your Private key
that has enough KLAY to truffle-config.js
WARNING: You shouldn't expose your private key. Otherwise, your account would be hacked.
networks
속성See networks
property above. klaytn
network has 4 properties,
provider
, network_id
, gas
, gasPrice
.
provider: () => new HDWalletProvider(PRIVATE_KEY, URL)
이름에서 알 수 있듯이 개인키와 위에 정의된 URL을 삽입합니다.
network_id: NETWORK_ID
Specify network id in Klaytn, you should set it to 1001
to use Klaytn Baobab network (testnet).
gas: GASLIMIT
지불하고자 하는 최대의 가스양입니다.
gasPrice: null
1 가스당 지불할 가격입니다. 현재 Klaytn에서는 1 가스당 가격이 25000000000
으로 고정되어 있습니다. null
로 설정하면 트러플에서 자동으로 고정 가스 가격이 설정됩니다.
compiler
속성Remember that for Solidity contract we used version 0.5.6, thus specify compiler version here.
migrations/2_deploy_contracts.js
:
You can specify which contract code will you deploy in your contracts/
directory.
Import your contract file (Klaystagram.sol
) via
const Klaystagram = artifacts.require('./Klaystagram.sol')
Use deployer
to deploy your contract, deployer.deploy(Klaystagram)
.
If you want to add more logic after deploying your contract, use .then()
(optional)
To save contracts' deployedABI
and deployedAddress
, use fs
node.js module
fs.writeFile(filename, content, callback)
(optional)
cf. For further information about artifacts.require()
, refer to truffle official documentation at truffle docs
In your terminal type $ truffle deploy --network baobab
.
It will deploy your contract according to truffle-config.js
and migrations/2_deploy_contracts.js
configuration.
Terminal will display deployed contract address if deployment was successful.
cf) --reset
option
If you provide this option, truffle will recompile and redeploy your contract even if contracts haven't changed.\ ex) $ truffle deploy --reset --network baobab