fabric-samples/asset-transfer-basic
Mark S. Lewis 63cc77bdc3
Avoid usage of deprecated ioutil Go package (#843)
* Refactor Go files
1. replace deprecated ioutil functions (ioutil is deprecated since Go 1.16)
2. fix variable names that collide with imported package name
3. fix typos

Also update Go version specified by Go modules to ensure a Go version is used in which ioutil is deprecated and replacement functions are available in os and io packages.

Signed-off-by: Tommy TIAN <xtianae@connect.ust.hk>
Co-authored-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

* Specify go 1.18 instead of go 1.19 in go.mod files

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

Signed-off-by: Tommy TIAN <xtianae@connect.ust.hk>
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
Co-authored-by: Tommy TIAN <xtianae@connect.ust.hk>
2022-10-25 07:04:39 -04:00
..
application-gateway-go Avoid usage of deprecated ioutil Go package (#843) 2022-10-25 07:04:39 -04:00
application-gateway-java Update samples to use fabric-gateway v1.1.1 (#842) 2022-10-20 17:43:55 +01:00
application-gateway-typescript Update samples to use fabric-gateway v1.1.1 (#842) 2022-10-20 17:43:55 +01:00
application-go Avoid usage of deprecated ioutil Go package (#843) 2022-10-25 07:04:39 -04:00
application-java Remove JCenter as a Gradle package repository (#589) 2022-01-26 16:29:09 -05:00
application-javascript * Made consistent lint command (#495) 2021-10-06 13:33:29 +01:00
application-typescript Update Javascript and Typescript Deps (#403) 2021-01-13 12:19:31 -05:00
application-typescript-hsm New HSM Typescript Sample (#455) 2021-07-06 11:48:34 +01:00
chaincode-external Avoid usage of deprecated ioutil Go package (#843) 2022-10-25 07:04:39 -04:00
chaincode-go Avoid usage of deprecated ioutil Go package (#843) 2022-10-25 07:04:39 -04:00
chaincode-java Use alpine based gradle image to build basic transfer java CC container 2022-08-03 12:07:20 -04:00
chaincode-javascript fix chaincode breakage in asset-transfer-basic (#694) 2022-03-31 08:38:05 +01:00
chaincode-typescript Fix vulnerabilities in typescript chaincode deps 2022-08-03 12:00:58 -04:00
rest-api-typescript Bump passport in /asset-transfer-basic/rest-api-typescript (#828) 2022-09-09 17:48:14 +02:00
.gitignore Adding NodeJS app for asset-transfer-basic sample. (#206) 2020-06-30 15:36:47 -04:00
README.md Add README to asset-transfer-basic sample (#638) 2022-02-10 13:52:46 +00:00

Asset transfer basic sample

The asset transfer basic sample demonstrates:

  • Connecting a client application to a Fabric blockchain network.
  • Submitting smart contract transactions to update ledger state.
  • Evaluating smart contract transactions to query ledger state.
  • Handling errors in transaction invocation.

About the sample

This sample includes smart contract and application code in multiple languages. This sample shows create, read, update, transfer and delete of an asset.

For a more detailed walk-through of the application code and client API usage, refer to the Running a Fabric Application tutorial in the main Hyperledger Fabric documentation.

Application

Follow the execution flow in the client application code, and corresponding output on running the application. Pay attention to the sequence of:

  • Transaction invocations (console output like "--> Submit Transaction" and "--> Evaluate Transaction").
  • Results returned by transactions (console output like "*** Result").

Smart Contract

The smart contract (in folder chaincode-xyz) implements the following functions to support the application:

  • CreateAsset
  • ReadAsset
  • UpdateAsset
  • DeleteAsset
  • TransferAsset

Note that the asset transfer implemented by the smart contract is a simplified scenario, without ownership validation, meant only to demonstrate how to invoke transactions.

Running the sample

The Fabric test network is used to deploy and run this sample. Follow these steps in order:

  1. Create the test network and a channel (from the test-network folder).

    ./network.sh up createChannel -c mychannel -ca
    
  2. Deploy one of the smart contract implementations (from the test-network folder).

    # To deploy the TypeScript chaincode implementation
    ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-typescript/ -ccl typescript
    
    # To deploy the Go chaincode implementation
    ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go/ -ccl go
    
    # To deploy the Java chaincode implementation
    ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java/ -ccl java
    
  3. Run the application (from the asset-transfer-basic folder).

    # To run the Typescript sample application
    cd application-gateway-typescript
    npm install
    npm start
    
    # To run the Go sample application
    cd application-gateway-go
    go run .
    
    # To run the Java sample application
    cd application-gateway-java
    ./gradlew run
    

Clean up

When you are finished, you can bring down the test network (from the test-network folder). The command will remove all the nodes of the test network, and delete any ledger data that you created.

./network.sh down