Step 5 - Build

FCT Engine

FCT platform enables the usage of multiple engines. Engines support different levels of transcoding and flavors of FCTL (FCT Language). The most versatile engine is called BatchMultiSig. It supports: variables, returned data from calls as inputs, multi-sig, recurrency, multi-party transactions, payment planning and much more.

Create Instance

const fct = new FCT.BatchMultiSigCall({ chainId })

Set Options

fct.setOptions({
    name: params.name,
    maxGasPrice: service.network.data.value.gasPrice,
})

Add Calls

Natively

When using native calls, there is a need to provide type data along with values

await fct.create({
  from, // vault (runner)
  to: <token_address>,
  method: 'transfer',
  params: [
    {
      name: 'recipient',
      type: 'address',
      value: <recipient_address>,
    },
    { name: 'amount', type: 'uint256', value: <token_amount> },
  ],
});

Using Plugins

plugins simplifies and secures the building of a call by providing type checks and data validations

await fct.create({
  from, // vault (runner)
  plugin: new plugins.ERC20.actions.Transfer({
    chainId: '1',
    initParams: {
      to: <token_address>,
      methodParams: {
        recipient: <recipient_address>,
        amount: <token_amount>,
      },
    },
  }),
});

Flow Control

Natively

Low level flow control is tricky because FCT do not allow cyclic referencing and values may be changed when call is added in the middle of the flow

await fct.create({
  ...,
  options: {
    flow: core.constants.Flow.OK_CONT_FAIL_REVERT,
    jumpOnSuccess?: 0,  // how many calls to jump over on success
    jumpOnFail?: 0,     // how many calls to jump over on fail
  },
})

// flow

OK_CONT_FAIL_REVERT         // default flow
OK_CONT_FAIL_CONT           // always continue
OK_CONT_FAIL_STOP           // stop of fail instead reverting
OK_STOP_FAIL_CONT           // stop on success, continue on fail
OK_STOP_FAIL_REVERT         // stop on success, revert on fail
OK_REVERT_FAIL_CONT         // revert on success, continue on fail
OK_REVERT_FAIL_STOP         // revert on success, stop on fail
 

Using Builder

For complex flow control it is recommended to use the builder, that simplifies the flow planning by compiling a higher level code to a flow and jump values and has a build-in mechanism to prevent cyclic flows.

fct.startWith(
  getMyKiroBalance.then(
    isGreaterThan1000
      .then(sendAllKiroToBob)
      .onFail(sendAllKiroToAlice)
  )
);

Last updated