Skip to content

veritas-L2/fabric-veritas-samples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Hyperledger Fabric Samples

Build Status

You can use Fabric samples to get started working with Hyperledger Fabric, explore important Fabric features, and learn how to build applications that can interact with blockchain networks using the Fabric SDKs. To learn more about Hyperledger Fabric, visit the Fabric documentation.

Getting started with the Fabric samples

To use the Fabric samples, you need to download the Fabric Docker images and the Fabric CLI tools. First, make sure that you have installed all of the Fabric prerequisites. You can then follow the instructions to Install the Fabric Samples, Binaries, and Docker Images in the Fabric documentation. In addition to downloading the Fabric images and tool binaries, the Fabric samples will also be cloned to your local machine.

Setup Veritas Test network

After you have setup all the HLF requirements, you can proceed to setup a Veritas Rollup TestNet.

Step 1: Setup Layer 1

Bring up two peer nodes and an orderer node.

cd test-network
./network.sh up

Now create a channel, l1, and make the two peer nodes join it.

./network.sh createChannel -c l1

Step 2: Setup Layer 2

Now we need to setup an Org3 that will contain a sequencer peer node. First generate certs for Org3, and create an l2 channel.

cd test-network
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=${PWD}/configtx

cd addOrg3
./addOrg3.sh generate

cd ..
configtxgen -profile L2Genesis -outputBlock ./channel-artifacts/l2.block -channelID l2
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export ORDERER_ADMIN_TLS_SIGN_CERT=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
export ORDERER_ADMIN_TLS_PRIVATE_KEY=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key
osnadmin channel join --channelID l2 --config-block ./channel-artifacts/l2.block -o localhost:7053 --ca-file "$ORDERER_CA" --client-cert "$ORDERER_ADMIN_TLS_SIGN_CERT" --client-key "$ORDERER_ADMIN_TLS_PRIVATE_KEY"

Now bring up the Org3 peer and make it join the l2 channel.

cd addOrg3
./addOrg3.sh up -c l2 

Step 3: Install the State Contract

The state contract manages the world state for the layer 2 rollup. Hence, it needs to be installed on the Org3 sequencer node. You can get the state contract from this repo.

After cloning the state contract repo, setup it's dependencies:

cd state-contract

#update the deps: HLF is unable to install this contract without this step at the moment. 
go get -u

#vendor deps
GO111MODULE=on go mod vendor

Now go back to the test-network directory and install the contract chaincode.

cd test-network/
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/

go run veritas-cli.go -name=state-contract -version=1.0 -sequence=1 -channel=l2 -org=Org3 -peerPort=<Org3 peer port> install-chaincode path/to/chaincode

Note: sequence should be in increasing order for each sequential update to a chaincode.

At this point, the state contract should be ready to receive invocations from applications and other chaincode on the l2 channel.

To install any chaincode on layer 2, follow the same chaincode installation steps described above.

Asset transfer samples and tutorials

The asset transfer series provides a series of sample smart contracts and applications to demonstrate how to store and transfer assets using Hyperledger Fabric. Each sample and associated tutorial in the series demonstrates a different core capability in Hyperledger Fabric. The Basic sample provides an introduction on how to write smart contracts and how to interact with a Fabric network using the Fabric SDKs. The Ledger queries, Private data, and State-based endorsement samples demonstrate these additional capabilities. Finally, the Secured agreement sample demonstrates how to bring all the capabilities together to securely transfer an asset in a more realistic transfer scenario.

Smart Contract Description Tutorial Smart contract languages Application languages
Basic The Basic sample smart contract that allows you to create and transfer an asset by putting data on the ledger and retrieving it. This sample is recommended for new Fabric users. Writing your first application Go, JavaScript, TypeScript, Java Go, JavaScript, TypeScript, Java
Ledger queries The ledger queries sample demonstrates range queries and transaction updates using range queries (applicable for both LevelDB and CouchDB state databases), and how to deploy an index with your chaincode to support JSON queries (applicable for CouchDB state database only). Using CouchDB Go, JavaScript Java, JavaScript
Private data This sample demonstrates the use of private data collections, how to manage private data collections with the chaincode lifecycle, and how the private data hash can be used to verify private data on the ledger. It also demonstrates how to control asset updates and transfers using client-based ownership and access control. Using Private Data Go, Java JavaScript
State-Based Endorsement This sample demonstrates how to override the chaincode-level endorsement policy to set endorsement policies at the key-level (data/asset level). Using State-based endorsement Java, TypeScript JavaScript
Secured agreement Smart contract that uses implicit private data collections, state-based endorsement, and organization-based ownership and access control to keep data private and securely transfer an asset with the consent of both the current owner and buyer. Secured asset transfer Go JavaScript
Events The events sample demonstrates how smart contracts can emit events that are read by the applications interacting with the network. README JavaScript, Java JavaScript
Attribute-based access control Demonstrates the use of attribute and identity based access control using a simple asset transfer scenario README Go None

Additional samples

Additional samples demonstrate various Fabric use cases and application patterns.

Sample Description Documentation
Commercial paper Explore a use case and detailed application development tutorial in which two organizations use a blockchain network to trade commercial paper. Commercial paper tutorial
Off chain data Learn how to use the Peer channel-based event services to build an off-chain database for reporting and analytics. Peer channel-based event services
Token ERC-20 Smart contract demonstrating how to create and transfer fungible tokens using an account-based model. README
Token UTXO Smart contract demonstrating how to create and transfer fungible tokens using a UTXO (unspent transaction output) model. README
Token ERC-1155 Smart contract demonstrating how to create and transfer multiple tokens (both fungible and non-fungible) using an account based model. README
Token ERC-721 Smart contract demonstrating how to create and transfer non-fungible tokens using an account-based model. README
High throughput Learn how you can design your smart contract to avoid transaction collisions in high volume environments. README
Simple Auction Run an auction where bids are kept private until the auction is closed, after which users can reveal their bid. README
Dutch Auction Run an auction in which multiple items of the same type can be sold to more than one buyer. This example also includes the ability to add an auditor organization. README
Chaincode A set of other sample smart contracts, many of which were used in tutorials prior to the asset transfer sample series.
Interest rate swaps Deprecated in favor of state based endorsement asset transfer sample
Fabcar Deprecated in favor of basic asset transfer sample

License

Hyperledger Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Hyperledger Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.

About

Veritas TestNet setup + sample chaincode

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 28.3%
  • JavaScript 26.9%
  • Java 17.1%
  • Shell 14.4%
  • TypeScript 13.1%
  • Dockerfile 0.2%