Receipt: the return value of wait

The wait method in MitumJS provides functionality for sending operations and polling until they are recorded on the blockchain. Users can verify whether the operation has ultimately been processed using wait.

The return value of the wait function, called 'receipt', is essentially the result of querying the operation with the fact hash of the operation sent through send. Therefore, depending on the success of the query, it also comes in two formats: SuccessResponse and ErrorResponse.

However, it's important to note that even if a SuccessResponse is returned, the success of the transaction processing is indicated by whether data.in_state is true or false.

If it's false, it means that the blockchain nodes have collectively decided not to process the transaction, with the reason specified in data.reason.

Check below for various responses of wait: success, failure, timeout examples.

Example of success

...

// Note: an asynchronous request.
const sendOperation = async () => {
    const info = await mitum.operation.send(signedOperation);
    const receipt = await info.wait();
    console.log(receipt);
};
sendOperation();

//output: SucessResponse example
//Note that data.in_state is true
{
  status: 200,
  method: 'get',
  url: 'http://127.0.0.1:24321/block/operation/CrLJkTrdZf4SmEKjEDeNQ57nqTX364eYveKW7SKUMxp3',
  request_body: undefined,
  data: {
    _hint: 'mitum-currency-operation-value-v0.0.1',
    hash: 'CrLJkTrdZf4SmEKjEDeNQ57nqTX364eYveKW7SKUMxp3',
    operation: {
      hash: 'FXmB36vahMQJkhZKXCqN96KfLcPAi9f5CY8KN3xbWJs4',
      fact: [Object],
      signs: [Array],
      _hint: 'mitum-currency-transfer-operation-v0.0.1'
    },
    height: 930510,
    confirmed_at: '2024-04-15T06:30:18.325Z',
    reason: '',
    in_state: true,
    index: 0
  }
}

Example of failure

...

// Note: an asynchronous request.
const sendOperation = async () => {
    const info = await mitum.operation.send(signedOperation);
    const receipt = await info.wait();
    console.log(receipt);
};
sendOperation();

//output: SucessResponse example
//Note that data.in_state is false
{
  status: 200,
  method: 'get',
  url: 'http://127.0.0.1:24321/block/operation/Rt7JhZRFFrBJnUmrbPBkPKuryS6NtDkgkW23SKGF9Dp',
  request_body: undefined,
  data: {
    _hint: 'mitum-currency-operation-value-v0.0.1',
    hash: 'Rt7JhZRFFrBJnUmrbPBkPKuryS6NtDkgkW23SKGF9Dp',
    operation: {
      hash: '8ah3qZShjsUV1FdabLQT5CAew9scSSRE5aDXzuHbptuu',
      fact: [Object],
      signs: [Array],
      _hint: 'mitum-currency-transfer-operation-v0.0.1'
    },
    height: 930588,
    confirmed_at: '2024-04-15T06:36:56.733Z',
    reason: 'check enough balance; insufficient balance of sender, 0xE8213471913c9dA4F4CcAB3Cc32Ec5a75d96d9cafca; 20 !> 21',
    in_state: false,
    index: 0
  }
}

As mentioned earlier, receiving a response in the SuccessResponse format with a status of 200 indicates successful querying of the operation, not necessarily successful processing of the operation itself. The crucial factor here is data.in_state.

If data.in_state is false, data.reason will indicate the cause of the failure. In the above example, it shows that the mitum node failed to process the transaction due to insufficient balance.

Example of timeout

...

// Note: an asynchronous request.
const sendOperation = async () => {
    const info = await mitum.operation.send(signedOperation);
    const receipt = await info.wait(12000, 1000);
    console.log(receipt);
};
sendOperation();

//output: ErrorResponse example
{
  status: undefined,
  method: 'get',
  url: 'http://127.0.0.1:24321/block/operation/3TrW49efwiitu2rRM23CH56ufDVboLE56W6a4vFU1hPJ',
  error_code: '',
  request_body: undefined,
  error_message: 'timeout reached (12 seconds).'
}

When calling wait method with timeout and interval parameters, polling occurs during that specified time interval. (If the parameters are not provided, default values are used.)

If the transaction is not queried from the blockchain during this specified time interval, a timeout error response, as described above, is received.

Last updated