Sui Programmable Transaction Block

A general Sui transaction is used mainly for invoking non-transfers transactions.

Fordefi can handle any Sui Programmable Transaction Block (PTB). While Sui PTB can be used to create transfers, it is recommended to use their request formats.

To invoke a general transaction using the Fordefi platform, you will only need to provide the binary canonical serialization (BCS) data of the request in base64 format.

When building the BCS data, make sure you are using commands that are supported by Fordefi:

  • Supported commands: merge_coins, split_coins, make_mov_vec, move_call, transfer_objects
  • Unsupported commands: publish, upgrade (Please contact us if you require support for these commands.)

When building the BCS data, you can pass 0 gas_budget, 0 gas_price or empty payment array if you’d like Fordefi to compute any of these fields for you. If these values are not empty, they will be used for the creation of the transaction.

📘

Note

API users must strongly authenticate transaction requests that are created programmatically by signing them. Learn more.

The following example creates a transaction request that adds liquidity to Cetus. The request should be inside the body, as demonstrated here. To learn more, visit the Sui blockchain explorer to view the transaction that was created by this code.

{
    "signer_type": "api_signer",
    "type": "sui_transaction",
    "details": {
        "type": "sui_binary_canonical_serialization",
        "chain": "sui_mainnet",
        "data": "AAAKAQCszKNyuM4wPiFvXHvlT/xuQhvaIKiHBKbbuv8gmjTIC65P7QUAAAAAIHsNXvA33dXqSF155/NKsU8LJa8mLtQ1zMCx4BU6rH3ZAAhjK1cAAAAAAAEB2qRikmMsPE2PMfI+oPmzaij/NnfpaEmA5EOEA6Z6PY8uBRgAAAAAAAABAQbYr55q/ScmLbQ28NN7MEoEH3EMPqH6TDqbqzazVprTaYodAAAAAAABAAS47AAAAAR8KAEAAAjQBwAAAAAAAAAIYytXAAAAAAAAAQEBAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAQAAAAAAAAAAAgIAAQEBAACPqrkCKOTE35HEFia7rvoZ/CXFFEBaxk3lRXjeyeb17g5wb29sX3NjcmlwdF92MihvcGVuX3Bvc2l0aW9uX3dpdGhfbGlxdWlkaXR5X2J5X2ZpeF9jb2luAgfAYABhEQFrigIK1bM4NJhKQ3qqfTx0wY4JqV1IrOqwjARjb2luBENPSU4ABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACA3N1aQNTVUkACgECAAEDAAEEAAEFAAEAAAIAAAEGAAEHAAEIAAEJAOSwXKixEKqsWkSxNAKyy1NLyD8ll2VzVLgUDzBJw4iEAmYyJrDN0EvxskLZ4lONh66ex3iy+q8FG3/IlxAjGAaOHCf+DwAAAAAgXCNjzpkUPSVf+9NSOPwILRtXoqiYJhKB1LQ5zDsanlOeY1q4umFhTuQ9WAG4Cn4Ze5oD8d5GEuCaXfDDD5E0POMn/g8AAAAAILqY2aH0K+yeWENsU0uNSttg4P9IZDSEi7V6HrpM9md05LBcqLEQqqxaRLE0ArLLU0vIPyWXZXNUuBQPMEnDiITvAgAAAAAAAPgsqgAAAAAAAA=="
    },
    "note": "Adding liquidity to Cetus",
    "vault_id": "8988893a-cf29-4a02-acc7-5bb723c74f47"
}
 

Building BCS data

Building the transaction BCS data can be done using any of the available Sui SDKs. One example is the @mysten/sui.js package.

The following example shows how to extract the BCS data from a transaction that we’ve built:

const client = new SuiClient({ url: getFullnodeUrl('mainnet') });
const tx = new TransactionBlock();

// This is the address of the vault used to create this transaction
tx.setSender('0x99746ebdb6813cefcc8d619edf7da78339933da7dab08e8792490d3a26f8f606');

// These are optional gas budget and price values. 
// They are not required if you'd like Fordefi to compute them for you.
tx.setGasBudget(1000000);
tx.setGasPrice(1000);

tx.splitCoins({ kind: 'GasCoin' }, [{ kind: 'Input', index: 0, type: 'pure', value: 10000000 }]);
tx.makeMoveVec({
  objects: [{ kind: 'NestedResult', index: 0, resultIndex: 0 }],
  type: 'vector<address>',
});
tx.object({
  Object: {
    Shared: {
      objectId: '0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c',
      initialSharedVersion: 64,
      mutable: false,
    },
  },
});

const bcsData = await tx.build({ client });

console.log(bcsData);
// This data should be converted to base64 and passed in the `details.data` 
// field of the Create Transaction request.