Use the Smart Contract API

This section lists the available Smart Contract API routes and their mandatory parameters.

Routes for executing smart contracts

This section lists the available routes for the smart contracts API and their mandatory parameters.

Note

You must first create a JWT token for the ng-rt-smartContracts plugin to execute these routes. Add the JWT token for ng-rt-smartContracts to the headers in your request.

Quick reference - chart

Method Route Description
POST /ng-rt-smartContracts/contracts/call/app/:contractId/:functionName Call method to read or update the smart contract memory
POST /ng-rt-smartContracts/contracts/app/:templateName Publish smart contract instance
POST /ng-rt-smartContracts/contracts/app/transferCall/:contractId/:functionName TransferCall method transfers the digital asset between two parties or to the smart contract
GET /ng-rt-smartContracts/contracts/:contractId  
GET /ng-rt-smartContracts/contracts/:contractId/state  
GET /ng-rt-smartContracts/contract-templates/:templateName  
GET /ng-rt-smartContracts/contract-templates  

Get your app key token

These calls use the application token ng-rt-smartContracts for authentication.

This call provides you the application token for ng-rt-smartContracts:

POST /auth/applogin

he following body parameters are mandatory:

  • "appID":"ng-rt-smartContracts"
  • "appKey":``<generated_app_key>

The response will return a JWT token needed for calls that require application authentication.

Publish

Use this method for publishing a new smart contract.

Note that if you choose the option to have the transaction signed by the client, no transaction ID will be returned.

The route for publishing a smart contract:

POST /ng-rt-smartContracts/contracts/app/:templateName

Include the following headers:

  • Authorization with the relevant JWT token
  • Content-Type: application/json

Replace :templateName with a Node-RED flow found in your TBSP instance.

The following parameters are mandatory:

  • pubKey - the public key of the client, required
  • args - enter a value (arg1@arg2@...@argN), required
  • clientSigning - the value is either true (signing of transaction by client) or false (signing of transaction by server)

Call

With the call method, you can either read the smart contract memory or update the smart contract memory.

The route for reading the smart contract memory:

POST /ng-rt-smartContracts/contracts/app/call/:contractId/getGreeting

Include the following headers:

  • Authorization with the relevant JWT token
  • Content-Type: application/json

Replace :functionName with the desired function. Note that no parameters are required for reading the smart contract memory.

The route for updating the smart contract memory:

POST /ng-rt-smartContracts/contracts/app/call/:contractId/changeGreeting

To update the smart contract, the following body parameters are mandatory:

  • pubKey - the public key of the client, required
  • args - enter a value (arg1@arg2@...@argN), required
  • clientSigning - the value is either true (signing of transaction by client) or false (signing of transaction by server)
  • asset_amount - enter an asset amount
  • asset_type - enter the type of digital asset

TransferCall

With the transferCall method, you can transfer a digital asset to another party or to a smart contract.

The route for transferring a digital asset:

POST /ng-rt-smartContracts/contracts/app/transferCall/:contractId/transferCall

Include the following headers:

  • Authorization with the relevant JWT token
  • Content-Type: application/json

To transfer a digital asset, the following parameters are mandatory:

  • pubKey - the public key of the client, required
  • args - enter a value (arg1@arg2@...@argN), required
  • assetId - enter the ID of the digital asset you would like to transfer, required
  • clientSigning - the value is either true (signing of transaction by client) or false (signing of transaction by server)
  • nextOwner - the public key of the asset's next owner - optional
  • amount - enter the amount of tokens - optional
  • latestTxId - enter the last transaction ID