This article takes Pet-Shop as an example to introduce how to deploy smart contract into smartBCH testnet using truffle.
Build smartbchd and generate a test key
Please flow this document to clone and build smartbchd. We need a test account and associated private key, smartbchd provides a sub-command to generate them for us:
$cdpath/to/your/smartbch/dir# and build smartbchd following the given doc$./smartbchdgen-test-keys-n1--show-address
The output looks like this (the generated private key and address are seperated by a space):
We need to install Node.js first, here are detailed information about how to install it on various platforms. Then, run the following cmd to install truffle:
$npminstall-gtruffle
And run the following cmd the see if truffle was installed successfully:
Modify truffle-config.js, add smartBCH testnet network configuration using you test key like bellow (you can find more smartBCH testnet RPC URLs here):
constHDWalletProvider=require('@truffle/hdwallet-provider');module.exports= {// See <http://truffleframework.com/docs/advanced/configuration>// for more about customizing your Truffle configuration! networks: { development: { host:"127.0.0.1", port:7545, network_id:"*"// Match any network id }, sbch_testnet: { network_id:"10001", gasPrice:0,provider: () =>newHDWalletProvider({ providerOrUrl:"http://35.220.203.194:8545", privateKeys: ["09c57df30208bdc056144c32d607f0719bdb0f8ac5f0a3259720d9e4d28d999b", ], }), } }};
Deploy Pet-Shop to smartBCH testnet
In directory pet-shop-tutorial, using truffle migrate cmd to deploy Pet-Shop contract into smartBCH testnet:
$trufflemigrate--networksbch_testnet
The output looks like this:
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'sbch_testnet'
> Network id: 10001
> Block gas limit: 200000000 (0xbebc200)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0xd03a612ec8ff3800fdaba8eab70230575cf5b6ed9c1eeecfa5595b20d7553281
> Blocks: 1 Seconds: 8
> contract address: 0x12033fAFdd217E1fF8F247D9C6E9a0606f75c813
> block number: 71514
> block timestamp: 1619962004
> account: 0xab83b691Bc12Aae947B2ca240F1732fa792dE246
> balance: 0.01
> gas used: 225225 (0x36fc9)
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_contracts.js
=====================
Deploying 'Adoption'
--------------------
> transaction hash: 0xc5137d30a6b065bfac3b6a3b8a321ffc338366c110e56315f9e601bca56e344b
> Blocks: 2 Seconds: 8
> contract address: 0x7D268085bDa90c0F9bC1c16c5bE6632958470B89
> block number: 71518
> block timestamp: 1619962024
> account: 0xab83b691Bc12Aae947B2ca240F1732fa792dE246
> balance: 0.01
> gas used: 203827 (0x31c33)
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
Summary
=======
> Total deployments: 2
> Final cost: 0 ETH
Wow! You have deployed Pet-Shop into smartBCH testnet. Thank you for testing smartBCH testnet 😊