Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Quick Start

jzhe edited this page Jul 20, 2020 · 19 revisions

We provide scripts for a quick interchain demo between two Fabric chains, which

include deploy and start Fabric blockchain, interchain gateway(Piers), and relay-chain(BitXHub).

Deploy Fabric Network

Before running the interchain network, the necessary software like Golang and Docker should be installed. Make sure that the environment variables such as $GOPATH, $GOBIN are set correctly.

After the above software is installed, we provide scripts to install and start two simple Fabric network.

Download and start Fabric network script(ffn.sh).

wget https://github.com/meshplus/goduck/raw/master/scripts/quick_start/ffn.sh

Start Fabric network:

Noting: Follow the instruction and confirm the config during script running.

// If local Fabric network is already running, shut it down first. Otherwise, ignore the command.
bash ffn.sh down 
// Start two Fabric network(appchain A and B).
bash ffn.sh up 

Noting: After the script running, there will be crypto-config and crypto-configB created in the present directory, The chaincode.sh and fabric_pier.sh showed below require the folders placed in the executing directory.

Deploy Interchain Contract

Download chaincode script(chaincode.sh):

wget https://raw.githubusercontent.com/meshplus/goduck/master/scripts/quick_start/chaincode.sh

Copy crypto-config and crypto-configB folder into the present directory, and run the following commands:

// appchain A deploys chaincode
// -c: Special configurations file for connecting to the fabric network, the default is config.yaml.
bash chaincode.sh install 
//appchain B deploys chaincode
bash chaincode.sh install -c 'configB.yaml' 

This command will deploy three chaincode(broker, transfer, anddata_swapper) on the Fabric network.

After deploying, use the following command to check whether the deploying is success.

// Query Alice's balance in appchain A.
// The previous step init an account called Alice which has 10000 balance.
// -c: Special configurations file for connecting to the fabric network, the default is config.yaml.
bash chaincode.sh get_balance -c 'config.yaml' 
****************************************************************************************************
***** | Response[0]: //peer0.org2.example.com
***** | | Payload: 10000
***** | Response[1]: //peer1.org2.example.com
***** | | Payload: 10000
****************************************************************************************************


// Query Alice's balance in appchain B.
bash chaincode.sh get_balance -c 'configB.yaml' 
****************************************************************************************************
***** | Response[0]: //peer0.org2.example1.com
***** | | Payload: 10000
***** | Response[1]: //peer1.org2.example1.com
***** | | Payload: 10000
****************************************************************************************************

Start BitXhub

BitXHub start script relies on golang and tmux. Please install the software before start.

Use commands below to clone the project:

git clone git@github.com:meshplus/bitxhub.git

BitXHub also relies on some small tools, use commands below to install:

cd bitxhub
git checkout v1.0.0-rc1
bash scripts/prepare.sh 

Finally, run the following commands to start a four nodes relay-chain.

make cluster

Noting: make cluster will use tmux to split the screen. Thus, during commands processing, better not switch the terminal.

Start interchain gateway

Download the related script(fabric_pier.sh):

wget https://github.com/meshplus/goduck/raw/master/scripts/quick_start/fabric_pier.sh

Run the following commands to start the pier:

// Start the interchain gateway to connect the app-chain A and BitXHub.
// -r: interchain gateway startup directory, default is .pier directory.
// -c: fabric organization certificate directory, the default is crypto-config.
// -g: Specify the configuration file for fabric cli connection, the default is config.yaml.
// -p: start port of the interchain gateway, the default is 8987.
// -b: GRPC address of the relay chain, the default is localhost: 60011.
// -o: pprof port, default is 44555.
bash fabric_pier.sh start -r '.pier' -c 'crypto-config' -g 'config.yaml' -p 8987 -b 'localhost:60011' -o 44555
// Start the interchain gateway to connect the app-chain B and BitXHub.
bash fabric_pier.sh start -r '.pierB' -c 'crypto-configB' -g 'configB.yaml' -p 8988 -b 'localhost:60011' -o 44556

Using the following commands to get the corresponding ID of the appchain which connected to the pier.

//ID of appchain A
bash fabric_pier.sh id -r '.pier'
//ID of appchain B
bash fabric_pier.sh id -r '.pierB'

Noting: The interchain commands require the ID.

Interchain Balance Transfer

Using the chaincode.sh which downloaded in Deploy Interchain Contract section to invoke relative chaincode.

  1. Query the balance of Alice
// Query Alice's balance in appchain A
// -c:Specify the configuration file for fabric cli connection, the default is config.yaml.
bash chaincode.sh get_balance -c 'config.yaml'
****************************************************************************************************
***** | Response[0]: //peer0.org2.example.com
***** | | Payload: 10000
***** | Response[1]: //peer1.org2.example.com
***** | | Payload: 10000
****************************************************************************************************


// Query Alice's balance in appchain B
bash chaincode.sh get_balance -c 'configB.yaml'.
****************************************************************************************************
***** | Response[0]: //peer0.org2.example1.com
***** | | Payload: 10000
***** | Response[1]: //peer1.org2.example1.com
***** | | Payload: 10000
****************************************************************************************************
  1. Send an interchain balance transaction

The following commands will transfer one Alice's token from one appchain to another.

// -c:Specify the configuration file for fabric cli connection, the default is config.yaml.
// -t: ID of destination chain (ID of appchain B)
bash chaincode.sh interchain_transfer -c 'config.yaml' -t <target_appchain_id>
  1. Query Balance

We query the balance of Alice on both app-chains:

// Query Alice's balance in the appchain A and find the balance reduced by a dollar.
// -c:Specify the configuration file for fabric cli connection, the default is config.yaml.
bash chaincode.sh get_balance -c 'config.yaml'
****************************************************************************************************
***** | Response[0]: //peer0.org2.example.com
***** | | Payload: 9999
***** | Response[1]: //peer1.org2.example.com
***** | | Payload: 9999
****************************************************************************************************


// Query Alice's balance in the application appchain B and find that the balance increased by a dollar.
bash chaincode.sh get_balance -c 'configB.yaml'
****************************************************************************************************
***** | Response[0]: //peer0.org2.example1.com
***** | | Payload: 10001
***** | Response[1]: //peer1.org2.example1.com
***** | | Payload: 10001
****************************************************************************************************

Noting: chaincode.sh calls the different Fabric networks, which means the different crypto-config folders are required. Attention the differentiation

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /