Introduction

This 15-minute tutorial shows you how to install the Car Dealer sample chaincode that is packaged with Oracle Blockchain Platform, deploy it on a channel, confirm that it is running, invoke basic transactions to add blocks to your ledger, and confirm that the new blocks have been added correctly.

Background

A blockchain platform implements a ledger of decentralized, tamper-proof data that is securely shared across a trusted business network. A blockchain is a continuously growing list of records, called blocks, which are linked and secured using cryptography.

Chaincodes define the data schema in the ledger, initialize it, perform updates when triggered by applications, and respond to queries. Chaincodes can also post events that allow applications to be notified and perform downstream operations.

Channels partition and isolate peers and ledger data to provide private and confidential transactions on the blockchain network. Members define and structure channels to allow specific peers to conduct private and confidential transactions that other members on the same blockchain network can't see or access. Each channel includes peers, the shared ledger, chaincodes instantiated on the channel, and one or more ordering service nodes.

Peer nodes contain a copy of the ledger and write transactions to the ledger. These nodes can also endorse transactions.

REST proxy nodes map an application identity to a blockchain member, which allows users and applications to call the Oracle Blockchain Platform REST APIs.

The Car Dealer sample includes a chaincode to manage the production, transfer, and querying of vehicle parts; the vehicles assembled from these parts; and the transfer of the vehicles. To run the sample, you need to complete the following steps:

  • Install the chaincode on one or more peers.
  • Deploy the chaincode on a channel.
  • Invoke the chaincode using a REST API call or an application.

You can download the sample to explore it more thoroughly, or to use it as a basis for your own chaincodes or applications.

Prerequisites

  • An Oracle Blockchain Platform founder instance.
  • Administrator access to your instance.
  • The URL of the Oracle Blockchain Platform console.
  • The channel (default) included with your instance.
  • The peers (peer0 and peer1) included with your instance and joined to the default channel.
  • The default REST proxy node (restproxy) included with your instance.

Task 1: Install the Sample

Installing is the act of putting the chaincode on a peer.

  1. Sign in to the Oracle Blockchain Platform service console using an administrative user ID.
  2. Click the Developer Tools tab.
  3. Click the Samples pane.
  4. In the Samples pane, locate the Car Dealer sample, and then click Install.
  5. On the Install CarDealer Chaincode dialog box, select peer0 from the Peers drop-down list, and click Install. Leave the Language drop-down list set to Golang.
  6. Click the Chaincodes tab. The Chaincodes Summary page is displayed, showing that the obcs-cardealer chaincode was packaged and given a package ID. Click 1 in the Installed on Peers column. The Installed on Peers Summary page is displayed, showing that the chaincode is installed on peer0.

Task 2: Deploy the Sample

Deploying a chaincode approves and commits a chaincode definition on the selected channel and peers where the chaincode was previously installed. The deploy transaction invokes the lifecycle chaincode (_lifecycle) to deploy a chaincode on a channel.

  1. In the Samples pane on the Developer Tools tab, locate the Car Dealer sample, and click Deploy. On the Deploy Chaincode dialog box, select the following and click Deploy
    • Channel: default
    Leave the Language drop-down list set to Golang.
  2. After the chaincode is deployed, go to the Chaincodes tab. For the package ID beginning with obcs-cardealer, click 1 in the Deployed on Channels column. The Deployed on Channels Summary page is displayed, showing that the chaincode is deployed on the default channel that you selected.
  3. On the Channels tab, click the default channel that you are running the sample chaincode on. Click the Deployed Chaincodes pane to confirm that there is one chaincode deployment on the channel, the obcs-cardealer chaincode.
    Description of deploy-channel.png follows
    Description of the illustration deploy-channel.png

Task 3: Invoke the Sample

Invoking is the process of calling chaincode functions. You'll use the applications included with the samples, although you could use direct REST API calls if you want to.

  1. On the Developer Tools tab, open the Samples pane, locate the Car Dealer sample, and click Invoke.
  2. On the Invoke Chaincode window, create a tire using the following information, and then click Execute:
    • Language: Golang
    • Channel: default
    • Action: Produce vehicle part
    • Serial Number: tr357
    • Owner: bobsmith
    • Name: tire357
    • Assembler: sevencorp
    • Assembly Date: Thursday, December 9, 2021
    Description of invoke-create-part.png follows
    Description of the illustration invoke-create-part.png
  3. On the Channels tab, locate and click the default channel.
  4. On the Ledger pane, locate the block number indicating that a data invocation occurred.
  5. Select the block, and confirm that in the Transactions table you see Success in the Status column.
  6. Click the arrow icon beside the transaction ID to display more information about the transaction.

    Note:

    Because you're invoking the Car Dealer chaincode, the obcs-cardealer chaincode is listed in the transaction. The function name is initVehiclePart because you've created a new part, and the transaction is endorsed by peer0 because that's the only peer you have chosen to endorse transactions on this channel.
  7. Description of invoke-create-ledger.png follows
    Description of the illustration invoke-create-ledger.png
  8. On the Developer Tools tab, open the Samples pane, locate the Car Dealer sample, and click Invoke.
  9. On the Invoke Chaincode window, enter the following values to query the tire you just created, and then click Execute:
    • Language: Golang
    • Channel: default
    • Action: Query vehicle part
    • Serial Number: tr357
  10. On the Channels tab, locate and click the default channel.
  11. On the Ledger pane, locate the block number of the most recent transaction.
  12. Click the block and confirm that in the Transactions table you see Success in the Status column.  Click the arrow icon next to the transaction ID to display more information about the transaction.

    Note:

    The correct chaincode, function name (readVehiclePart), and endorsing peer (peer0) should be listed.
  13. Description of invoke-query.png follows
    Description of the illustration invoke-query.png
  14. On the Developer Tools tab, open the Samples pane, locate the Car Dealer sample, and click Invoke.
  15. On the Invoke Chaincode window, enter the following values to transfer the ownership of the tire to a new user, and then click Execute:
    • Language: Golang
    • Channel: default
    • Action: Transfer vehicle part
    • Serial Number: tr357
    • Owner: anniechu
  16. On the Channels tab, locate and click the default channel.
  17. On the Ledger pane, locate the block number of the most recent transaction.
  18. Click the block, click the arrow icon next to the transaction ID to display more information about the transaction, and confirm that in the Transactions table you see Success in the Status column.

    Note:

    The correct chaincode, function name (transferVehiclePart), and endorsing peer (peer0) should be listed.
  19. Description of invoke-transfer.png follows
    Description of the illustration invoke-transfer.png

You can delete a chaincode if it is no longer needed. For more information, see Delete a Chaincode

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.