📝
smartbch
  • Introduction
  • Whitepaper
  • FAQ
  • Mainnet
  • Testnets
  • Join Amber testnet as a Validator
  • Developer's Guide
    • Introduction
    • Deploy contracts using Truffle
    • Deploy contracts using Remix
    • JSON-RPC Endpoints
    • Staking Scheme
    • XHedge Smart Contract
    • Decision of the minimum gas price
  • Sha-Gate Bridge
    • Sha-Gate Specification
    • Sha-Gate Risk Analysis
    • Sha-Gate's Covenant
  • In-Depth Design Documents
    • Introduction
    • MoeingADS's General Ideas
    • MoeingADS's RabbitStore
    • MoeingADS's internal architecture
    • Benchmarking MoeingADS
    • Benchmarking MoeingEVM and MoeingADS
    • Benchmarking Testnet
    • Transaction Reordering in smartBCH
    • Transaction Parallel Execution in smartBCH
    • Send back-to-back Transactions
    • Data structures in world state
  • SmartBCH Evolution Proposals (SEPs)
    • SEP101: Store values with arbitrary length
    • SEP102: Adjustment of Used Gas
    • SEP109: On-chain Verification of Verifiable Random Functions
    • SEP18: Blockchain cheques on smartBCH
    • SEP20: Tokens on smartBCH
    • SEP206: Manipulate Native Token as a SEP20 Token
    • SEP201: Simple Stochastic Payment
  • Archives
    • Single Node Private Testnet
    • Multi-Node Testnet
    • Fake RPC Server for Testing
    • Test using MetaMask
Powered by GitBook
On this page
  • Build smartbchd and generate a test key
  • Install Truffle
  • Clone Pet-Shop and add testnet config
  • Deploy Pet-Shop to smartBCH testnet

Was this helpful?

  1. Developer's Guide

Deploy contracts using Truffle

PreviousIntroductionNextDeploy contracts using Remix

Last updated 2 years ago

Was this helpful?

This article takes as an example to introduce how to deploy smart contract into smartBCH testnet using .

Build smartbchd and generate a test key

Please flow 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-address

The output looks like this (the generated private key and address are seperated by a space):

09c57df30208bdc056144c32d607f0719bdb0f8ac5f0a3259720d9e4d28d999b 0xab83b691Bc12Aae947B2ca240F1732fa792dE246

Go to to fund our newly generated address some BCH.

Install Truffle

We need to install Node.js first, are detailed information about how to install it on various platforms. Then, run the following cmd to install truffle:

$ npm install -g truffle

And 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.9

Clone Pet-Shop and add testnet config

Using git clone cmd to clone pet-shop source code into you local directory:

$ cd somedir
$ git clone https://github.com/trufflesuite/pet-shop-tutorial.git
$ cd pet-shop-tutorial
$ npm install @truffle/[email protected] --save-dev
const HDWalletProvider = 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: () => new HDWalletProvider({
        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:

$ truffle migrate --network sbch_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 😊

Install 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 ):

Pet-Shop
truffle
this document
smartBCH testnet faucet
here
truffle hdwallet-provider
here