Send a Transaction
post
/restproxy/api/v2/channels/{channelName}/transactions
This endpoint is used to send a transaction. Note that for asynchronous transactions, we suggest using the new Send an Asynchronous Transaction endpoint.
Request
Supported Media Types
- application/json
Path Parameters
-
channelName(required): string
Name 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:
falseSpecifies if 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:
falseSpecifies if it should select endorsers of this organization only. When set to true, the endorsers field cannot be specified. -
sync:
boolean
Default Value:
falseWhether to invoke the chaincode synchronously. -
timeout:
integer(int64)
Default Value:
18000Timeout in ms for the chaincode to invoke -
transientMap:
object transientMap
Additional Properties Allowed: additionalPropertiesTransientMap for the chaincode
-
txid:
string
ID of the transaction
Nested Schema : transientMap
Type:
objectAdditional 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:
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
Operation successful 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
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
401 Response
Unauthorized
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
403 Response
Forbidden
404 Response
Not Found
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
500 Response
Internal Server Error
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
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:
txidandnonceare the values generated using the Get a New Transaction ID and Nonce endpoint.chaincodeis the chaincode ID of the balance transfer sample chaincode.argsspecify the chaincode function to be invoked along with it's parameters. For the balance transfer sample chaincode you can use the following arguments:initbecause this chaincode requires explicit initialization. Note that you also need to set theisInitparameter to true.invokewhen invoking the chaincode.
isInitspecifies that you're initializing the chaincode. If your chaincode requires initialization, this must be done before invoking any other transactions.timeoutspecifies the maximum number of milliseconds for the transaction to timeout.syncwith 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.