send(operation, ?: headers)
Feature
Send the signed operation to the RPC node for broadcasting to the network. Note: Even if the response data is received successfully, it does not guarantee that the operation will be processed. Always check the operation's facthash to see if the operation was processed.
Parameters
HintedObject
| Operation<Fact>
signed operation,
null
| object
http header (optional)
Return Value
object
OperationResponse
[OperationResponse’s structure ]
{
response: SuccessResponse || ErrorResponse,
_api: api address,
_delegateIP: delegateIP,
}
example
// Make any raw operation you want to send
const rawOperation = mitum.currency.transfer(sender, receiver, currencyID, amount);
// Add signature to the rawOperation
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 (If sending is successful)
{
status: 200,
method: 'post',
url: 'http://127.0.0.1:24321/builder/send',
request_body: '{"_hint":"mitum-currency-transfer-operation-v0.0.1","fact":{"_hint":"mitum-currency-transfer-operation-fact-v0.0.1","hash":"FVDe8yznGuNFEJ1opcnuHgPFj6597JtxhzbusyTKCnez","token":"MjAyNC0wNC0wNSAwNDowOToyNi41NTEgKzAwMDAgVVRD","sender":"0xe1842cCaAf7Df28467ECFdFbD3bdB7de84dEDC3Dfca","items":[{"_hint":"mitum-currency-transfer-item-multi-amounts-v0.0.1","amounts":[{"_hint":"mitum-currency-amount-v0.0.1","currency":"MIT","amount":"10"}],"receiver":"0x626410F061e62d79294f82603b872Db7d1711Bf7fca"}]},"hash":"6jygiNgKCxvFPHScuwFZzcM5QChx642KyzZgS9kPfkyb","memo":"","signs":[{"signer":"26vyVJFoLZqVPmP8UADoNCsEyJYD4498vdy7uoiHgFKRUmpu","signature":"381yXYmPea3ospSqT8cG2QBLiAgoyNThmH7XTTwtjXzB4waHBpqo8KAWP6UMWUvgk1v9psuvDCYUfT7uX7pvbBr475QNZ8j3","signed_at":"2024-04-05T04:09:26.553Z"}]}',
data: {
hash: '6jygiNgKCxvFPHScuwFZzcM5QChx642KyzZgS9kPfkyb',
fact: {
hash: 'FVDe8yznGuNFEJ1opcnuHgPFj6597JtxhzbusyTKCnez',
token: 'MjAyNC0wNC0wNSAwNDowOToyNi41NTEgKzAwMDAgVVRD',
_hint: 'mitum-currency-transfer-operation-fact-v0.0.1',
sender: '0xe1842cCaAf7Df28467ECFdFbD3bdB7de84dEDC3Dfca',
items: [Array]
},
signs: [ [Object] ],
_hint: 'mitum-currency-transfer-operation-v0.0.1'
}
}
// output (If sending is failed)
{
status: 400,
method: 'post',
url: 'http://127.0.0.1:24321/builder/send',
error_code: 'P06D502',
request_body: '{"_hint":"mitum-currency-transfer-operation-v0.0.1","fact":{"_hint":"mitum-currency-transfer-operation-fact-v0.0.1","hash":"FVDe8yznGuNFEJ1opcnuHgPFj6597JtxhzbusyTKCnez","token":"MjAyNC0wNC0wNSAwNDowOToyNi41NTEgKzAwMDAgVVRD","sender":"0xe1842cCaAf7Df28467ECFdFbD3bdB7de84dEDC3Dfca","items":[{"_hint":"mitum-currency-transfer-item-multi-amounts-v0.0.1","amounts":[{"_hint":"mitum-currency-amount-v0.0.1","currency":"MIT","amount":"10"}],"receiver":"0x626410F061e62d79294f82603b872Db7d1711Bf7fca"}]},"hash":"6jygiNgKCxvFPHScuwFZzcM5QChx642KyzZgS9kPfkyb","memo":"","signs":[{"signer":"26vyVJFoLZqVPmP8UADoNCsEyJYD4498vdy7uoiHgFKRUmpu","signature":"381yXYmPea3ospSqT8cG2QBLiAgoyNThmH7XTTwtjXzB4waHBpqo8KAWP6UMWUvgk1v9psuvDCYUfT7uX7pvbBr475QNZ8j3","signed_at":"2024-04-05T04:09:26.553Z"}]}',
error_message: 'handle new operation PreProcess: Account not found: sender account, ...'
}
Last updated