Response: the return value of sending transaction
When sending transactions to the blockchain using the send
and touch
functions, various issues may arise.
The result of send transactions is referred to as the response
, which, like the result of the GET
function, comes in two formats: SuccessResponse
and ErrorResponse
.
The most immediate cause of failure to consider is the failure of transaction transmission due to network disruptions or abnormal states of nodes.
Even if the transaction is successfully transmitted to a functioning node, it might still be rejected by the blockchain.
In cases of rejection, MitumJS provides additional information through specific error codes to offer more detailed insights.
Example of success
// import Mitum Object first, see import Mitum section
const mitum = new Mitum("http://127.0.0.1:24321");
const sender = "0xE8213471913c9dA4F4CcAB3Cc32Ec5a75d96d9cafca";
const receiver = "0x728E21B1F8bD5D91856cb68C12337dAbB7f84BEFfca";
const privatekey = "83e195b7a12a6aa99baa7310c045289041fe18f797398d8ec93bb027feee5f32fpr";
const currencyID = "ABC";
const op = mitum.currency.transfer(sender, receiver, currencyID, amount);
const signedOperation = mitum.operation.sign(privatekey, op);
// Note: an asynchronous request.
const sendOperation = async () => {
const info = await mitum.operation.send(signedOperation);
console.log(info.response);
};
sendOperation();
//output: SucessResponse example
{
status: 200,
method: 'post',
url: 'http://127.0.0.1:24321/builder/send',
request_body: '{"_hint":"mitum-currency-transfer-operation-v0.0.1","fact":{...},"signed_at":"2024-04-15T05:29:45.955Z"}]}',
data: {
hash: '4feUEuvHzzezMpSAcBYLZ1YMM82DrteyP6yFZR9iFxMC',
fact: {
hash: 'EL2PXmFp153CEwt9mVRtvT9gX91mfr5a67fU4kk3rVb',
token: 'MjAyNC0wNC0xNSAwNToyOTo0NS45NTMgKzAwMDAgVVRD',
_hint: 'mitum-currency-transfer-operation-fact-v0.0.1',
sender: '0xE8213471913c9dA4F4CcAB3Cc32Ec5a75d96d9cafca',
items: [Array]
},
signs: [ [Object] ],
_hint: 'mitum-currency-transfer-operation-v0.0.1'
}
}
Example of failure
...
// Note: an asynchronous request.
const sendOperation = async () => {
const info = await mitum.operation.send(signedOperation);
console.log(info.response);
};
sendOperation();
//output: ErrorResponse example
{
status: 400,
method: 'post',
url: 'http://127.0.0.1:24321/builder/send',
error_code: 'P06D201',
request_body: '{"_hint":"mitum-currency-transfer-operation-v0.0.1","fact":{},"memo":"","signs":[{"signer":"26vyVJFoLZqVPmP8UADoNCsEyJYD4498vdy7uoiHgFKRUmpu","signature":"381yXZ7brFzKcgZ1WXV3rEzbYrUa2JuhCWhA1iErsgEb45JuwUHHiNsVvLZVL5mRQiYXgpHQJ6xCXNBtSfo9zyejgekxvGiB","signed_at":"2024-05-09T03:15:26.979Z"}]}',
error_message: 'handle new operation: PreProcess: Invalid signing: Check threshold; Unknown key found, 0386ef65c156747d3c9da5600f27b581c2a824426b3584e800369169f2ae0f8c4afpu'
}
The above failure example is when an operation reaches the blockchain properly, but the operation is not permitted. In this case, mitumJS classifies the error case by error_code
and provides additional information. For the definition of error_code
, please refer here.
Last updated