Skip to content

build

The build method creates transaction instructions based on different action types. It supports building various types of instructions including default transactions, bridge intents, transfers, approvals, and withdrawals.

Parameters

ParameterTypeRequiredDescription
baseParamsBaseInstructionsParamsYesBase configuration for building instructions
baseParams.accountBaseMultichainSmartAccountYesThe multichain smart account to check balances for
baseParams.currentInstructionsInstruction[]NoArray of existing instructions to append to
parametersBuildInstructionTypesYesThe build action configuration
parameters.type"default" | "intent" | "transfer" | "transferFrom" | "approve" | "withdrawal"YesThe type of build action
parameters.dataVarious (see below)YesAction-specific parameters based on the type

Build Action Types

Default Instructions (type: "default")

type BuildDefaultParameters = {
  calls: {
    to: Address
    value?: bigint
    gasLimit?: bigint
    data?: Hex
  }[]
  chainId: number
}

Bridge Intent (type: "intent")

type BuildIntentParameters = {
  amount: bigint
  mcToken: MultichainToken
  toChain: Chain
}

Transfer (type: "transfer")

type BuildTransferParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  recipient?: Address
}

Transfer From (type: "transferFrom")

type BuildTransferFromParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  sender: Address
  recipient: Address
}

Approve (type: "approve")

type BuildApproveParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  spender: Address
}

Withdrawal (type: "withdrawal")

type BuildWithdrawalParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  recipient?: Address
}

Returns

Promise resolving to an array of Instruction containing:

PropertyTypeDescription
chainIdnumberChain ID where the instruction will be executed
callsCall[]Array of contract calls to execute
calls[].toAddressTarget contract address
calls[].valuebigintAmount of native tokens to send
calls[].gasLimitbigintGas limit for the call
calls[].dataHexEncoded call data

Examples

Bridge Intent Example

const bridgeInstructions = await mcAccount.build({
  type: "intent",
  data: {
    amount: parseUnits("1", 6), // 1 USDC
    mcToken: mcUSDC,
    toChain: optimism
  }
});

Token Transfer Example

const transferInstructions = await mcAccount.build({
  type: "transfer",
  data: {
    chainId: optimism.id,
    tokenAddress: mcUSDC.addressOn(optimism.id),
    amount: parseUnits("1", 6),
    recipient: "0x..."
  }
});

Token Approval Example

const approvalInstructions = await mcAccount.build({
  type: "approve",
  data: {
    chainId: optimism.id,
    tokenAddress: mcUSDC.addressOn(optimism.id),
    amount: parseUnits("1", 6),
    spender: "0x..."
  }
});

Default Transaction Example

const defaultInstructions = await mcAccount.build({
  type: "default",
  data: {
    calls: [{ 
      to: "0x...",
      value: 0n,
      gasLimit: 50000n
    }],
    chainId: optimism.id
  }
});

Error Handling

The method will throw an error if:

  • Unknown build action type is provided
  • Invalid instruction parameters are provided
  • Required parameters are missing
  • Chain ID is invalid
  • Token address is invalid

Type Definitions

BuildInstructionTypes

type BuildInstructionTypes =
  | BuildDefaultInstruction
  | BuildIntentInstruction
  | BuildTransferInstruction
  | BuildTransferFromInstruction
  | BuildApproveInstruction
  | BuildWithdrawalInstruction

BuildDefaultInstruction

type BuildDefaultInstruction = {
  type: "default"
  data: BuildDefaultParams
}

BuildIntentInstruction

type BuildIntentInstruction = {
  type: "intent"
  data: BuildIntentParameters
}

BuildTransferInstruction

type BuildTransferInstruction = {
  type: "transfer"
  data: BuildTransferParameters
}

BuildTransferFromInstruction

type BuildTransferFromInstruction = {
  type: "transferFrom"
  data: BuildTransferFromParameters
}

BuildApproveInstruction

type BuildApproveInstruction = {
  type: "approve"
  data: BuildApproveParameters
}

BuildWithdrawalInstruction

type BuildWithdrawalInstruction = {
  type: "withdrawal"
  data: BuildWithdrawalParameters
}

BuildDefaultParams

type BuildDefaultParams = {
  calls: {
    to: Address
    value?: bigint
    gasLimit?: bigint
    data?: Hex
  }[]
  chainId: number
}

BuildIntentParameters

type BuildIntentParameters = {
  amount: bigint
  mcToken: MultichainToken
  toChain: Chain
}

BuildTransferParameters

type BuildTransferParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  recipient?: Address
}

BuildTransferFromParameters

type BuildTransferFromParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  sender: Address
  recipient: Address
}

BuildApproveParameters

type BuildApproveParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  spender: Address
}

BuildWithdrawalParameters

type BuildWithdrawalParameters = {
  chainId: number
  tokenAddress: Address
  amount: bigint
  gasLimit?: bigint
  recipient?: Address
}