要加入Hyperledger Fabric 1.4作为新成员,需要执行以下步骤:
-
安装必要的软件:
-
克隆Hyperledger Fabric源代码库:
git clone https://github.com/hyperledger/fabric.git
-
切换到1.4版本的分支:
git checkout release-1.4
-
构建Fabric二进制文件:
cd fabric
make release
-
部署Fabric网络:
-
创建一个新目录,用于存储Fabric网络的配置和证书文件:
mkdir mynetwork
cd mynetwork
-
复制Fabric示例网络的配置文件:
cp -r $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/* .
-
生成网络的加密材料和创世区块:
cryptogen generate --config=./crypto-config.yaml
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
-
启动网络:
docker-compose -f docker-compose-cli.yaml up -d
-
运行应用程序:
-
安装Fabric Node SDK:
npm install fabric-ca-client fabric-network
-
创建一个JavaScript文件,并编写代码连接到Fabric网络:
const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');
const ccpPath = path.resolve(__dirname, 'connection.json');
async function main() {
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = new FileSystemWallet(walletPath);
const userExists = await wallet.exists('user1');
if (!userExists) {
console.log('An identity for the user "user1" does not exist in the wallet');
return;
}
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: false } });
const network = await gateway.getNetwork('mychannel');
const contract = network.getContract('mychaincode');
const result = await contract.submitTransaction('createAsset', 'asset1', 'blue', '10', 'Tom');
console.log('Transaction has been submitted');
await gateway.disconnect();
}
main().then(() => {
console.log('Application finished successfully');
}).catch((error) => {
console.error(`Application error: ${error}`);
});
-
在mychannel
通道上运行名为createAsset
的智能合约。
以上是一个简单的示例,演示了如何加入Hyperledger Fabric 1.4作为新成员并与网络进行交互。你可以根据自己的需求进一步扩展和定制。