Smart Contract #4 - Vehicle Transfer

This smart contract involves the creation of a digital asset and the transfer of this asset between different owners with a specific acceptance condition.

This smart contract involves the following steps:

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


In a terminal session, create a digital asset and assign it the type vehicle, specifying unique properties in its jsonAssetData:

tymlez-sc createAsset --type=sample_vehicle --jsonAssetData='{"type":"BMW", "color":"red", "serialNo":1234}'

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,

[ERROR] - There is no inspection date... Please provide inspection date...

set the inspection date of the digital asset within the last year in the format 2019-01-03, for example:

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

The inspection date is then set:

[INFO] - contract ID: 37afc2a3b939390225c0cbd9af0ab2bf239d293d660ab101404a42e17e877a82
[INFO] - Signed tx...
[INFO] - Post signed tx ....
[INFO] - 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:

{ serverType: 'http',
serverUrl: '',
pwdPolicy: 'prompt',
storage: 'main',
plugins: { 'ng-rt-admin': [Object], 'ng-rt-digitalAsset': [Object] },
userCredentials: [ [Object], [Object] ],
{ 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] - contractId: 150ef0893078a1cf1505feb77d931c18a613475457150f91dffb5661b9ad6ae6
[INFO] - please sign the contract
[INFO] - Signed tx...
[INFO] - Post signed tx ....
[INFO] - tx Id: 63fd55f43af1d1cddad55fb02c747d026d0e099594175eddc0a8a352313b35a2
[INFO] - Smart Contract transferred successfully!!!

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

[INFO] - contractId: 37afc2a3b939390225c0cbd9af0ab2bf239d293d660ab101404a42e17e877a82
[ERROR] commands.transferCall - Please do the inspection soon.


Alternatively, you can run the vehicle transfer smart contract flow entirely with the Smart Contract Explorer, found here.

Return to the smart contracts main page