Before You Begin
This 15-minute tutorial shows you how to install the Car Dealer sample chaincode that is packaged with Oracle Blockchain Platform, instantiate 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 is a system for maintaining distributed ledgers of facts and the history of the ledger’s updates. 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:
- Install the chaincode on one or more peers.
- Instantiate the chaincode on a channel and enable it on REST proxy nodes.
- 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.
What Do You Need?
- An Oracle Blockchain Platform founder instance. You can't delete chaincodes that have been deployed, so create a new Oracle Blockchain Platform Developer instance for the sample network if possible.
- Administrator access.
- The URL of the Oracle Blockchain Platform console.
Install
the Sample
Installing is the act of putting the chaincode on a peer.
- Sign in to the Oracle Blockchain Platform console using an administrative user ID.
- Select the Developer Tools tab.
- Click the Samples pane.
- In the Samples pane, locate the Car Dealer sample, and click Install.
- On the Install CarDealer Chaincode dialog, select
peer0
from the Peers drop-down list, and click Install. - Click
1
in the Installed on Peers field; it listspeer0
on which you have installed the chaincode.
Instantiate
the Sample
Instantiating a chaincode compiles, builds, and initializes the chaincode on the selected channel and peers where the chaincode was previously installed. The instantiate transaction invokes the Lifecycle System Chaincode (LSCC) to create and initialize a chaincode on a channel.
- In the Samples pane, locate the Car Dealer
sample, and click Instantiate. On the
Instantiate Chaincode dialog, select the following and click Instantiate
and Enable in REST Proxy:
- Channel:
default
- REST proxy:
restproxy1
.
- Channel:
- Click
1
on the Instantiated on channels field; it shows thedefault
channel you've selected to use. - On the Channels tab, click the
default
channel that you are running the sample chaincode on. In the Channel Information page, click the Instantiated Chaincodes pane to confirm that there is one chaincode deployment on the channel, theobcs-cardealer
chaincode.Description of the illustration instantiate-channel.png - Click the Ledger pane and confirm that the
Ledger Summary has one new block added in addition to the
genesis block, indicating one deployment occurred. In the
Ledger table, locate the block with the Type of data
(sys). Select the block and in the Transaction
table, click the arrow icon to display more information about
the block.
Confirm that the Function Name field displays deploy. Confirm that the transaction lists the Chaincode as
lscc
as opposed to the Car Dealer chaincode.Description of the illustration instantiate-ledger.png
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 click then Execute:
- Channel:
default
- Action:
Produce vehicle part
- Serial Number:
tr357
- Owner:
bobsmith
- Name:
tire357
- Assembler:
sevencorp
- Assembly Date:
08/09/18
Description of the illustration invoke-create-part.png - Channel:
- On the Channels tab, locate and click the
default
channel. - Open the Ledger pane, and 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.
Because you're invoking the Car Dealer chaincode, the
obcs-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:
- Channel:
default
- Action:
Query vehicle part
- Serial Number:
tr357
- Channel:
- On the Channels tab, locate and click the
default
channel. - Open the Ledger pane, and 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.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:
- Channel:
default
- Action:
Transfer vehicle part
- Serial Number:
tr357
- Owner:
anniechu
- Channel:
- On the Channels tab, locate and click the
default
channel. - Open the Ledger pane, and 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.The correct chaincode, function name (
transferVehiclePart
), and endorsing peer (peer0
) should be listed.


