Smart Contract #4 - Vehicle Transfer

In a multi-node network, this smart contract will also place a call to all nodes and retrieve information from a single node (the node whose IP address is specified in your .tymlez/config.json).

This smart contract involves the following steps:

  • Creation of a digital asset definition called vehicle
  • Creation of a digital asset
  • Creation of a smart contract with specific acceptance condition
  • Transfer of the asset from one owner to another owner

Steps

In a terminal session, create a digital asset and assign it the type car:

tymlez-sc createAsset --type=car

This will return the asset ID of the digital asset you created:

[INFO] commands.createAsset - Signed tx...
[INFO] commands.createAsset - Post signed tx ....
[INFO] commands.createAsset - Asset Id: cee02c0f047679f7382c20754c20ddc9e8dc66c17d594781990bbfc32b0a4bfd

Create a smart contract, specifying the asset ID of the digital asset from the previous step:

tymlez-sc publish --templateName=SC_vehicleTransfer <ASSET_ID>

The contract ID will then be returned:

[INFO] commands.publish - publishing contract SC_vehicleTransfer....
[INFO] commands.publish - Signed tx...
[INFO] commands.publish - Post signed tx ....
[INFO] commands.publish - Smart Contract published successfully
[INFO] commands.publish - Contract id: 37afc2a3b939390225c0cbd9af0ab2bf239d293d660ab101404a42e17e877a82

Check if an inspection date has already been assigned to the digital asset:

tymlez-sc call --functionName=getLastInspectionDate

If you see the following,

[INFO] commands.call - There is no inspection date... Please provide inspection date...

Set the inspection date of the digital asset within the last year from to in the format 2019-01-3, for example:

tymlez-sc call --functionName=setInspectionDate "<YYYY-MM-D>"

The inspection date is then set:

[INFO] commands.call - contract ID: 37afc2a3b939390225c0cbd9af0ab2bf239d293d660ab101404a42e17e877a82
[INFO] commands.call - Signed tx...
[INFO] commands.call - Post signed tx ....
[INFO] commands.call - Smart Contract updated !!!

Check if the inspection date has been set:

tymlez-sc call --functionName=getLastInspectionDate

In the next step, obtain the public key of the next owner:

tymlez-dev config getAllContext

All environments will be then displayed. Copy the public key from the previously cloned environment, cloud1 to the clipboard:

cloud1:
{ serverType: 'http',
serverUrl: '192.168.50.10:8143',
pwdPolicy: 'prompt',
storage: 'main',
plugins: { 'ng-rt-admin': [Object], 'ng-rt-digitalAsset': [Object] },
userCredentials: [ [Object], [Object] ],
keypair:
{ public: '8fNmXPUkPcLznrzQHb5zR7L6SyRA7wBAuo5CDWEFusyF',
private: '5v3dP6ajR3FLmYdV3j7gUFuRfveAzcBDXG4XVgJ4XS4U' } } }

Execute the smart contract, pasting the public key from the clipboard:

tymlez-sc transferCall --functionName=transferVehicle --assetId=<ASSET_ID_FROM_ABOVE> --nextOwner=<PUBLIC_KEY_OF_NEXT_OWNER>

If the inspection has happened within the last year, the transfer transaction is successful:

[INFO] commands.call - contractId: 150ef0893078a1cf1505feb77d931c18a613475457150f91dffb5661b9ad6ae6
[INFO] commands.call - please sign the contract
[INFO] commands.call - Signed tx...
[INFO] commands.call - Post signed tx ....
[INFO] commands.call - tx Id: 63fd55f43af1d1cddad55fb02c747d026d0e099594175eddc0a8a352313b35a2
[INFO] commands.call - Smart Contract transferred successfully!!!

If the inspection took place more than one year ago, the transfer transaction is rejected by the receiving party:

[INFO] commands.call - contractId: 37afc2a3b939390225c0cbd9af0ab2bf239d293d660ab101404a42e17e877a82
[INFO] commands.call - Transaction rejected by Smart Contract

Return to the smart contracts main page

Ready for more? Discover the advanced functions of TBSP on Google Cloud here.