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
andpeer1
) included with your instance and joined to thedefault
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.
- Sign in to the Oracle Blockchain Platform service console using an administrative user ID.
- Click the Developer Tools tab.
- Click the Samples pane.
- In the Samples pane, locate the Car Dealer sample, and then click Install.
- 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 toGolang
. - Click the Chaincodes tab. The Chaincodes Summary page is displayed, showing that the
obcs-cardealer
chaincode was packaged and given a package ID. Click1
in the Installed on Peers column. The Installed on Peers Summary page is displayed, showing that the chaincode is installed onpeer0
.
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.
- 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
Golang
. - Channel:
- After the chaincode is deployed, go to the Chaincodes tab.
For the package ID beginning with
obcs-cardealer
, click1
in the Deployed on Channels column. The Deployed on Channels Summary page is displayed, showing that the chaincode is deployed on thedefault
channel that you selected. - 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, theobcs-cardealer
chaincode.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.
- On the Developer Tools tab, open the Samples pane, locate the Car Dealer sample, and click Invoke.
- 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 the illustration invoke-create-part.png - Language:
- On the Channels tab, locate and click the
default
channel. - On the Ledger pane, locate the block number indicating that a data invocation occurred.
- Select the block, and confirm that in the Transactions table
you see
Success
in the Status column. - Click the arrow icon beside the transaction ID to display
more information about the transaction.
Note:
Because you're invoking the Car Dealer chaincode, theobcs-cardealer
chaincode is listed in the transaction. The function name isinitVehiclePart
because you've created a new part, and the transaction is endorsed bypeer0
because that's the only peer you have chosen to endorse transactions on this channel. - On the Developer Tools tab, open the Samples pane, locate the Car Dealer sample, and click Invoke.
- 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
- Language:
- On the Channels tab, locate and click the
default
channel. - On the Ledger pane, locate the block number of the most recent transaction.
- 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. - On the Developer Tools tab, open the Samples pane, locate the Car Dealer sample, and click Invoke.
- 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
- Language:
- On the Channels tab, locate and click the
default
channel. - On the Ledger pane, locate the block number of the most recent transaction.
- 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.



You can delete a chaincode if it is no longer needed. For more information, see Delete a Chaincode
Related Links
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.
Install, Deploy, and Invoke a Sample Chaincode
F34752-03
November 2022
Copyright © 2021-2022, Oracle and/or its affiliates.