Actions

Set action options

It is possible to set some options to every action method in order to change the gas limit, gas price or to separate the action instantiation from the execution.
JavaScript & Node
1
//Returns the action not executed
2
const action = await defire.actions.methodXXX(param1, .., paramN, {
3
execute: false
4
});
5
6
//Executes the action and returns the final response
7
const response = await defire.actions.methodXXX(param1, .., paramN, {
8
execute: true
9
});
Copied!
Method parameters
opts optionalobject :
    gasLimit optional BN (Ethereum transaction gas limit)
    gasPrice optional BN (Ethereum transaction gas price)
    execute optional bool (True if the action should execute and return a promise or false if it should return an action object. Default: true)
    autoAllowTokens optional bool (Defines if an action that needs token allowance should auto approve them. Default: true)
Returns
This method returns a Promise which resolves with the documented action response or an action object the option execute is set to true.

Action object

It contains the information and methods about a action.
Object fields
status enum:
    0 Not executed
    1 Executing
    2 Succeeded
    3 Failed
Current status of the action execution.
hash string
When the action has status 1,2 or 3 it contains the Ethereum transaction hash.
txParams object:
    gasLimit string (Transaction gas limit in hexadecimal format)
    gasPrice string (Transaction gas price in hexadecimal format)
    to string (Transaction to address)
    from string (Transaction from address)
    value string (Transaction value in hexadecimal format)
Transaction information to be executed.
result any
The final response of the action method as documented.

Execute method

JavaScript & Node
1
//Executes the action, not wait to finish and return the action updated.
2
const action = await action.execute(false);
3
4
//Executes the action and returns the final response
5
const response = await action.execute(true);
Copied!
Method parameters
wait required bool
True if the action should execute and wait for the final response. False if should execute but not wait for the transaction to finish.
Returns
This method returns a Promise which resolves with the documented action response if the option wait is set to true or the action object updated if the option wait is set to false.

Update status method

This method checks the current status of the transaction that the action is executing and update the status field of the action. If the transaction finished and it was successful, it also updates the result field of the action.
JavaScript & Node
1
//Updates the action.status and action.result
2
//depending on the status of the transaction.
3
await action.updateStatus();
Copied!
Last modified 1yr ago