Deploy contracts using Truffle
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:
$ cd path/to/your/smartbch/dir # and build smartbchd following the given doc
$ ./smartbchd gen-test-keys -n 1 --show-addressThe output looks like this (the generated private key and address are seperated by a space):
09c57df30208bdc056144c32d607f0719bdb0f8ac5f0a3259720d9e4d28d999b 0xab83b691Bc12Aae947B2ca240F1732fa792dE246Go to smartBCH testnet faucet to fund our newly generated address some BCH.
Install Truffle
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:
$ npm install -g truffleAnd run the following cmd the see if truffle was installed successfully:
$ truffle version
Truffle v5.1.63 (core: 5.1.63)
Solidity v0.5.16 (solc-js)
Node v15.10.0
Web3.js v1.2.9Clone Pet-Shop and add testnet config
Using git clone cmd to clone pet-shop source code into you local directory:
Install truffle hdwallet-provider v1.2.6 (for some unknown reason, the latest version v1.3.x may not work with private keys, so we use v1.2.x here):
Modify truffle-config.js, add smartBCH testnet network configuration using you test key like bellow (you can find more smartBCH testnet RPC URLs here):
Deploy Pet-Shop to smartBCH testnet
In directory pet-shop-tutorial, using truffle migrate cmd to deploy Pet-Shop contract into smartBCH testnet:
The output looks like this:
Wow! You have deployed Pet-Shop into smartBCH testnet. Thank you for testing smartBCH testnet 😊
Last updated
Was this helpful?