Send a Transaction

post

/restproxy/api/v2/channels/{channelName}/transactions

Send a transaction.

Request

Supported Media Types
Path Parameters
Body ()
Request to invoke a transaction
Root Schema : schema
Type: object
Show Source
Nested Schema : args
Type: array
Arguments for the chaincode
Show Source
Nested Schema : endorsers
Type: array
Endorsers for the chaincode
Show Source
Nested Schema : transientMap
Type: object
Additional Properties Allowed
Show Source
Transient map for the chaincode
Back to Top

Response

Supported Media Types

201 Response

Successful operation for synchronous transaction
Body ()
Root Schema : schema
Type: object
Show Source
Nested Schema : result
Type: object
Show Source

202 Response

Successful operation for asynchronous transaction
Body ()
Root Schema : schema
Type: object
Show Source
Nested Schema : result
Type: object
Show Source

400 Response

Bad Request

401 Response

Not authorized

403 Response

Forbidden

404 Response

Invalid parameters

500 Response

Service unavailable
Back to Top

Examples

This endpoint is used to invoke an asynchronous transaction providing a new transaction ID and nonce.

Note:

Before invoking this endpoint, you must generate a new asynchronous transaction ID and nonce using the Get a New Transaction ID and Nonce endpoint.

The following example shows how to invoke an asynchronous transaction by submitting a POST request on the REST resource using cURL.

curl -v -u <username>:<password> -X POST \
  "https://<rest proxy of your blockchain instance>/api/v2/channels/<channel_name>/transactions" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  --data @<JSON file with the request parameters>

For example,

curl -v -u <username>:<password> -X POST \
  "https://myvm.oracle.com:10001/restproxy/api/v2/channels/default/transactions" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" 
  --data @file.json
To initialize the balance transfer sample chaincode, the contents of file.json would be similar to:
{
 "chaincode": "obcs-example02",
 "args": [ "init","a","100","b","200" ],
 "isInit": true,
 "timeout": 18000,    
 "sync": true
}
To invoke the balance transfer sample chaincode, the contents of file.json would be similar to:
{
 "txid": "bb248ef3f948cb107417c3f66ea144910644dee8086a370d44687fd9fe262233",
 "nonce": "b508e30891a738162a35ebd1b7f768f8e8520111e4201dd9",
 "chaincode": "obcs-example02",
 "args": [ "invoke","a","b","200" ],
 "timeout": 18000,
 "sync": false
}
Where:
  • txid and nonce are the values generated using the Get a New Transaction ID and Nonce endpoint.
  • chaincode is the chaincode ID of the balance transfer sample chaincode.
  • args specify the chaincode function to be invoked along with it's parameters. For the balance transfer sample chaincode you can use the following arguments:
    • init because this chaincode requires explicit initialization. Note that you also need to set the isInit parameter to true.
    • invoke when invoking the chaincode.
  • isInit specifies that you're initializing the chaincode. If your chaincode requires initialization, this must be done before invoking any other transactions.
  • timeout specifies the maximum number of milliseconds for the transaction to timeout.
  • sync with a false value indicates that this is not a synchronous transaction.

Note:

You can find the REST proxy value of your Blockchain instance from the Nodes tab of your instance console.

Example of the Response Body

The following example shows the contents of the response body in JSON format:

{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "bb248ef3f948cb107417c3f66ea144910644dee8086a370d44687fd9fe262233",
        "payload": null,
        "encode": ""
    }
}

In this case, the value returned for payload is null because the chaincode function invoked was not a chaincode query and therefore, it did not return any value.

Back to Top