Skip to main content

SDK Actions

A number of SDK methods return actions. These actions can be one of two types:

  • ActionType.TRANSACTION - an action that is executed when a transaction is sent to the blockchain
  • ActionType.SIGNABLE - an action that is executed when a message is signed and submitted through a subsequent SDK call

Actions are returned in order, so it is safe to iterate over them. The following code block is an example of how one might execute all actions:

import { providers } from 'ethers';
import { orderbook } from '@imtbl/sdk';

// Sign and submit all transaction actions. Collect and return all signatures from signable actions.
export async function actionAll(
actions: orderbook.Action[],
provider: providers.Web3Provider,
): Promise<string[]> {
const signer = await provider.getSigner()

const signatures: string[] = [];
for (const action of actions) {
if (action.type === orderbook.ActionType.TRANSACTION) {
const transaction = await action.buildTransaction();
const signedTx = await signer.sendTransaction(transaction);
await signedTx.wait();
}
if (action.type === orderbook.ActionType.SIGNABLE) {
const signature = await signer._signTypedData(
action.message.domain,
action.message.types,
action.message.value,
);

signatures.push(signature);
}
}

return signatures;
}

IMX Whitepaper IMX Tokenomics Block Explorer Careers Contact Us