Testing smartBCH SHA-Gate2 Testnet Using CLI

Testing smartBCH SHA-Gate2 Testnet Using CLI

Related GitHub repos:

SHA-Gate2 Testnet Services:

Note:

  • The smartBCH SHA-Gate2 is under active development and this doc will be updated according to it.

Step0, Prepare

  1. Install Git
  2. Install Node.js
  3. Install ts-node

Step1, Generate a BCH testnet P2PKH address

You can use cc-covenant/scripts/make-cc-utxo.ts to do this:

$ git clone https://github.com/smartbch/cc-covenant
$ cd cc-covenant
$ npm install
$ MNEMONIC=cindy ts-node scripts/make-cc-utxo.ts list-utxo # replace cindy with your favorite name

The above command prints something like this:

WIF     : L54T1iWuRBwwye9snRgr6T6cNDFoubhfgnaFDwAhZMV8KCtNJrqK
Pubkey  : 02b20605271c9bfed2728b75dbf7c042855a6d32e9e627e2e87b617cd0f269cc05
PKH     : 9b30e8592c267cdfe0f3ecbda76d6ad85696b5b0
CashAddr: bchtest:qzdnp6ze9sn8ehlq70ktmfmddtv9d944kqujnheqaw
quering UTXOs ...
utxos: []

Your BCH testnet address is bchtest:qzdnp6ze9sn8ehlq70ktmfmddtv9d944kqujnheqaw and it has no BCH balance (UTXOs). You can send this address some test BCH through faucets like this one. After that, you can query it again:

...
quering UTXOs ...
utxos: [
  {
    txid: 'db63e97ecad9a9588a6109f0eb9c0e2c03e84d1a784c3b2731d22a68d38c4e73',
    vout: 0,
    satoshis: 10100000,
    height: 0
  }
]

Step2, Transfer BCH to smartBCH

To transfer BCH from BCH testnet to smartBCH testnet, you need to know the SHA-Gate2 testnet cc-covenant P2SH address. You can use cc-covenant/cc-covenant-testnet.ts to query it:

$ cd cc-covenant
$ ts-node cc-covenant-testnet.ts print-covenant-info

The above command prints a lot of information, what we care about now is the last three lines:

...
redeemScriptHash: 6ad3f81523c87aa17f1dfa08271cf57b6277c98e
cashAddr: bchtest:pp4d87q4y0y84gtlrhaqsfcu74akya7f3c54m3nhzk
oldAddr: 2N2z5YVDehL1TAmMJbWmXimnFF6d5iA45VY

The cc-covenant address is bchtest:pp4d87q4y0y84gtlrhaqsfcu74akya7f3c54m3nhzk. Now, you can send this address some BCH using cc-covenant/script/make-cc-utxo.ts:

$ cd cc-covenant
$ MNEMONIC=cindy ts-node scripts/make-cc-utxo.ts spend-utxo \
	--to=bchtest:pp4d87q4y0y84gtlrhaqsfcu74akya7f3c54m3nhzk \
	--utxo=db63e97ecad9a9588a6109f0eb9c0e2c03e84d1a784c3b2731d22a68d38c4e73:0 \
	--amt=200000 \
	--txfee=1000 \
	--retdata=0xAb5D62788E207646fA60EB3eEbDC4358C7F5686c

The subcommand is spend-utxo, and the options are:

  • to: the cc-covenant address
  • utxo: the txid and vout of your UTXO, separated by a colon
  • amt: the transfer amount in Satoshi
  • txfee: the tx fee you give BCH miner in Satoshi
  • retdata: the recipient address on the smartBCH side

The command will print BCH tx detail like this:

{
  "inputs": [
    {
      "outpointIndex": 0,
      "outpointTransactionHash": "<Uint8Array: 0xdb63e97ecad9a9588a6109f0eb9c0e2c03e84d1a784c3b2731d22a68d38c4e73>",
      "sequenceNumber": 4294967295,
      "unlockingBytecode": "<Uint8Array: 0x4830450221009ae4d311a5c53df2e536fa43f409b468838ac1510e9eb9c0bda1e5ee2c932c1602204e2e21fdc14c58ee15d18a807f3dc88651d35978740a3cbcdbcb14016deaf7bc412102b20605271c9bfed2728b75dbf7c042855a6d32e9e627e2e87b617cd0f269cc05>"
    }
  ],
  "locktime": 0,
  "outputs": [
    {
      "lockingBytecode": "<Uint8Array: 0xa9146ad3f81523c87aa17f1dfa08271cf57b6277c98e87>",
      "satoshis": "<Uint8Array: 0x400d030000000000>"
    },
    {
      "lockingBytecode": "<Uint8Array: 0x76a9149b30e8592c267cdfe0f3ecbda76d6ad85696b5b088ac>",
      "satoshis": "<Uint8Array: 0xf80b970000000000>"
    },
    {
      "lockingBytecode": "<Uint8Array: 0x6a2a307841623544363237383845323037363436664136304542336545624443343335384337463536383663>",
      "satoshis": "<Uint8Array: 0x0000000000000000>"
    }
  ],
  "version": 2,
  "txid": "a2e84c3c2ec3e536583f3a20ee9948c5972712eb33c3aa77e5c93d8e7c41a585",
  "hex": "0200000001734e8cd3682ad231273b4c781a4de8032c0e9cebf009618a58a9d9ca7ee963db000000006b4830450221009ae4d311a5c53df2e536fa43f409b468838ac1510e9eb9c0bda1e5ee2c932c1602204e2e21fdc14c58ee15d18a807f3dc88651d35978740a3cbcdbcb14016deaf7bc412102b20605271c9bfed2728b75dbf7c042855a6d32e9e627e2e87b617cd0f269cc05ffffffff03400d03000000000017a9146ad3f81523c87aa17f1dfa08271cf57b6277c98e87f80b9700000000001976a9149b30e8592c267cdfe0f3ecbda76d6ad85696b5b088ac00000000000000002c6a2a30784162354436323738384532303736343666413630454233654562444334333538433746353638366300000000"
}

You can also watch your tx using BCH testnet explorer. After about 3 confirmations, the cc-UTXO will be handled by smartBCH testnet.

Step3, startRescan and handleUTXO by Hand

The SHA-Gate2 testnet need cc-monitor’s help to work. Normally, the cc-monitor will do its job, but in case it doesn’t you can do it by yourself. You can use this command to see the latest BCH height that the SHA-Gate2 testnet handled:

$ curl -X POST --data '{"jsonrpc":"2.0","method":"sbch_getCcInfo","params":[],"id":1}' \
   -H "Content-Type: application/json" http://18.141.161.139:8545 | jq

It prints something like this:

    "lastCovenantAddress": "0x0000000000000000000000000000000000000000",
    "currCovenantAddress": "0x6Ad3f81523c87aa17f1dFA08271cF57b6277C98e",
    "lastRescannedHeight": 1529816,
    "rescannedHeight": 1529818,
    "rescanTime": 1670383139,
    "utxoAlreadyHandled": false,

If its fall behind, use this command to tell it to catch up:

$ git clone https://github.com/smartbch/cc-contracts.git
$ cd cc-contracts
$ npm install
$ KEY=0x<your SHA-Gate2 testnet private key> \
	HARDHAT_NETWORK=shagate_test1 \
	node scripts/cc_test_tool.js start-rescan --height 1529827

Wait a while, and use this command to tell it to handle cc-UTXOs:

$ cd cc-contracts
$ KEY=0x<your SHA-Gate2 testnet private key> \
	HARDHAT_NETWORK=shagate_test1 \
	node scripts/cc_test_tool.js handle-utxos

Then, you can query redeemable cc-UTXOs use this command:

$ curl -X POST -H "Content-Type: application/json" --data '{
  "jsonrpc":"2.0",
  "method":"sbch_getRedeemableUtxos",
  "params":[],
  "id":1
}' http://18.141.161.139:8545 | jq

The output looks like this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "infos": [
      {
        "ownerOfLost": "0x0000000000000000000000000000000000000000",
        "covenantAddr": "0x6ad3f81523c87aa17f1dfa08271cf57b6277c98e",
        "isRedeemed": false,
        "redeemTarget": "0x0000000000000000000000000000000000000000",
        "expectedSignTime": 0,
        "txid": "0x7832ade94f5d0998baff1a91373b5f7e93ce278fad323fcc6783b772517503a9",
        "index": 0,
        "amount": "0x30d40",
        "txSigHash": "0x"
      },
      {
        "ownerOfLost": "0x0000000000000000000000000000000000000000",
        "covenantAddr": "0x6ad3f81523c87aa17f1dfa08271cf57b6277c98e",
        "isRedeemed": false,
        "redeemTarget": "0x0000000000000000000000000000000000000000",
        "expectedSignTime": 0,
        "txid": "0xa2e84c3c2ec3e536583f3a20ee9948c5972712eb33c3aa77e5c93d8e7c41a585",
        "index": 0,
        "amount": "0x30d40",
        "txSigHash": "0x"
      }
    ],
    "signature": "0xc30389b7ee45686fea012e4a00da7cc534391bd43bddd4720fbb9988e4bf61da27efcaed9f8db848506984339282e5fb493ed30149093e51f3734540db88b30701"
  }
}

Step4, redeem BCH

You can transfer BCH from smartBCH testnet to BCH testnet by redeeming one of redeemable cc-UTXOs. For example:

$ cd cc-contracts

$ KEY=0x<your SHA-Gate2 testnet private key> \
	HARDHAT_NETWORK=shagate_test1 \
  node scripts/cc_test_tool.js redeem \
    --txid=0xa2e84c3c2ec3e536583f3a20ee9948c5972712eb33c3aa77e5c93d8e7c41a585 \
    --index=0 \
    --amount=0.002 \
    --to=0x9b30e8592c267cdfe0f3ecbda76d6ad85696b5b0

This time, we use redeem subcommand. The options are:

  • txid: the txid of redeemable cc-UTXO
  • index: the vout of redeemable cc-UTXO
  • amount: the value of cc-UTXO in BCH
  • to: the recipient address on the BCH side (the PKH part in step1’s output)

Please wait a while to let SHA-Gate2 testnet and its coordinators (cc-operators and cc-collector) handle the transfer. Congrats, you just finished your test on smartBCH SHA-Gate2 testnet. We are still working hard at improving the SHA-Gate2 now, thank you for your patience.

3 Likes

how long does it take for BCH to be credited (spendable) as SBCH?

and how long does it take for SBCH to be redeemed back to BCH?

It is about 2 ~ 3 BCH testnet3 blocks

same as above

2 Likes

oh wow! okay that’s impressive :+1:

looking forward to testing this out asap

1 Like