Send a Transaction
post
/restproxy/api/v2/channels/{channelId}/transactions
Send a transaction
Request
Supported Media Types
- application/json
Path Parameters
-
channelId: string
ID of the channel
Request to invoke a transaction
Root Schema : schema
Type:
Show Source
object
-
args:
array args
Arguments for the chaincode
-
chaincode:
string
ID of the chaincode to invoke
-
endorsers(optional):
array endorsers
Endorsers for the chaincode
-
nonce(optional):
string
Nonce for the transaction
-
role(optional):
string
Name of the Fabric enrollment to be used
-
sync(optional):
boolean
Default Value:
false
Whether to invoke the chaincode synchronously -
timeout(optional):
integer(int64)
Default Value:
18000
Timeout in ms for the chaincode to invoke -
transientMap(optional):
object transientMap
Additional Properties Allowed: additionalPropertiesTransientMap for the chaincode
-
txid(optional):
string
ID of the transaction
Nested Schema : transientMap
Type:
object
Additional Properties Allowed
Show Source
TransientMap for the chaincode
Response
Supported Media Types
- application/json
201 Response
Operation successful for synchronous transaction
Root Schema : schema
Type:
Show Source
object
-
error(optional):
string
Default Value:
-
result(optional):
object result
-
returnCode:
string
Allowed Values:
[ "Success", "Failure" ]
Nested Schema : result
Type:
Show Source
object
-
encode:
string
Allowed Values:
[ "UTF-8", "JSON", "base64" ]
-
message(optional):
string
-
payload:
-
txid:
string
202 Response
Operation successful for asynchronous transaction
Root Schema : schema
Type:
Show Source
object
-
error(optional):
string
Default Value:
-
result(optional):
object result
-
returnCode:
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 -u <username>:<password> -X POST \ "https://<rest proxy of your blockchain instance>/api/v2/channels/default/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
The contents of
file.json
are:
{ "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.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 restproxy 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.