Send a Transaction
post
/restproxy/api/v2/channels/{channelName}/transactions
Send a transaction.
Request
Supported Media Types
- application/json
Path Parameters
-
channelName(required): string
ID of the channel
Request to invoke a transaction
Root Schema : schema
Type:
Show Source
object
-
args(required):
array args
Arguments for the chaincode
-
chaincode(required):
string
ID of the chaincode to invoke
-
endorsers:
array endorsers
Endorsers for the chaincode
-
isInit:
boolean
Default Value:
false
Whether it is an initialization request -
nonce:
string
Nonce for the transaction
-
role:
string
Name of the Hyperledger Fabric enrollment to be used
-
sameOrgEndorser:
boolean
Default Value:
false
Whether it should select endorsers of this org only. When set to true, endorsers cannot be specified. -
sync:
boolean
Default Value:
false
Whether to invoke the chaincode synchronously -
timeout:
integer(int64)
Default Value:
18000
Timeout in ms for the chaincode to invoke -
transientMap:
object transientMap
Additional Properties Allowed: additionalPropertiesTransient map for the chaincode
-
txid:
string
ID of the transaction
Nested Schema : transientMap
Type:
object
Additional Properties Allowed
Show Source
Transient map for the chaincode
Response
Supported Media Types
- application/json
201 Response
Successful operation for synchronous transaction
Root Schema : schema
Type:
Show Source
object
-
error:
string
Default Value:
-
result:
object result
-
returnCode(required):
string
Allowed Values:
[ "Success", "Failure" ]
Nested Schema : result
Type:
Show Source
object
-
encode(required):
string
Allowed Values:
[ "UTF-8", "JSON", "base64" ]
-
message:
string
-
payload(required):
-
sourceURL:
string
Returns the URL of the peer that reported the transaction status to the rest proxy.
-
txid(required):
string
202 Response
Successful operation for asynchronous transaction
Root Schema : schema
Type:
Show Source
object
-
error:
string
Default Value:
-
result:
object result
-
returnCode(required):
string
Allowed Values:
[ "Success", "Failure" ]
400 Response
Bad Request
401 Response
Not authorized
403 Response
Forbidden
404 Response
Invalid parameters
500 Response
Service unavailable
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 -X POST \ "https://<rest proxy of your blockchain instance>/api/v2/channels/<channel_name>/transactions" \ -H "Authorization: Bearer <OAuth_access_ token>" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @<JSON file with the request parameters>
For example,
curl -v -X POST \ "https://myvm.oracle.com:10001/restproxy/api/v2/channels/default/transactions" \ -H "Authorization: Bearer mF_9.B5f-4.1JqM" \ -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
andnonce
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 theisInit
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.