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 need to provide the following:

  • The gas configuration, if relevant
  • An array of inputs
  • An array of commands:
    • Supported commands: merge_coins, split_coins, make_mov_vec, move_call, transfer_objects
    • Not supported commands: publish, upgrade

Any transaction must have at least one input and one command.

πŸ“˜

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_programmable_transaction_block",  
        "chain": "sui_mainnet",  
        "gas_config": {
            "budget": "11152632",
            "price": "751",
            "payment": [
                {
                    "digest": "7CfopLdVTrT6a9eBwjDr6p9JrdtEgjJabmCC3jwxKXop",
                    "object_id": "0x663226b0cdd04bf1b242d9e2538d87ae9ec778b2faaf051b7fc897102318068e",
                    "version": "268314396"
                },
                {
                    "digest": "DZQ1mSfH2GGrnvWHkgoz4MqbNeveEmBDYcDLNHS8irtB",
                    "object_id": "0x9e635ab8ba61614ee43d5801b80a7e197b9a03f1de4612e09a5df0c30f91343c",
                    "version": "268314595"
                }
            ]
        },
        "inputs": [
            {
                "type": "object",
                "details": {
                    "digest": "9HLyP4T5RZNMEcdXbiQPYnKDpXk8iGCr9vAF8vT2ysJg",
                    "object_id": "0xaccca372b8ce303e216f5c7be54ffc6e421bda20a88704a6dbbaff209a34c80b",
                    "version": "99438510",
                    "type": "imm_or_owned"
                }
            },
            {
                "type": "pure",
                "details": {
                    "value": {
                        "type": "byte_array_pure_input",
                        "value": "YytXAAAAAAA="
                    }
                }
            },
            {
                "type": "object",
                "details": {
                    "type": "shared",
                    "object_id": "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",
                    "initial_shared_version": "1574190",
                    "mutable": false
                }
            },
            {
                "type": "object",
                "details": {
                    "type": "shared",
                    "object_id": "0x06d8af9e6afd27262db436f0d37b304a041f710c3ea1fa4c3a9bab36b3569ad3",
                    "initial_shared_version": "1935977",
                    "mutable": true
                }
            },
            {
                "type": "pure",
                "details": {
                    "value": {
                        "type": "byte_array_pure_input",
                        "value": "uOwAAA=="
                    }
                }
            },
            {
                "type": "pure",
                "details": {
                    "value": {
                        "type": "byte_array_pure_input",
                        "value": "fCgBAA=="
                    }
                }
            },
            {
                "type": "pure",
                "details": {
                    "value": {
                        "type": "byte_array_pure_input",
                        "value": "0AcAAAAAAAA="
                    }
                }
            },
            {
                "type": "pure",
                "details": {
                    "value": {
                        "type": "byte_array_pure_input",
                        "value": "YytXAAAAAAA="
                    }
                }
            },
            {
                "type": "pure",
                "details": {
                    "value": {
                        "type": "byte_array_pure_input",
                        "value": "AQ=="
                    }
                }
            },
            {
                "type": "object",
                "details": {
                    "type": "shared",
                    "object_id": "0x0000000000000000000000000000000000000000000000000000000000000006",
                    "initial_shared_version": "1",
                    "mutable": false
                }
            }
        ],
        "commands": [
            {
                "type": "split_coins",
                "coin_object": {
                    "type": "gas_coin"
                },
                "amounts": [
                    {
                        "type": "input",
                        "index": 1
                    }
                ]
            },
            {
                "type": "move_call",
                "arguments": [
                    {
                        "type": "input",
                        "index": 2
                    },
                    {
                        "type": "input",
                        "index": 3
                    },
                    {
                        "type": "input",
                        "index": 4
                    },
                    {
                        "type": "input",
                        "index": 5
                    },
                    {
                        "type": "input",
                        "index": 0
                    },
                    {
                        "type": "result",
                        "index": 0
                    },
                    {
                        "type": "input",
                        "index": 6
                    },
                    {
                        "type": "input",
                        "index": 7
                    },
                    {
                        "type": "input",
                        "index": 8
                    },
                    {
                        "type": "input",
                        "index": 9
                    }
                ],
                "target": "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee::pool_script_v2::open_position_with_liquidity_by_fix_coin",
                "type_arguments": [
                    "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
                    "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
                ]
            }
        ]
    },  
    "note": "Adding liquidity to Cetus",  
    "vault_id": "8988893a-cf29-4a02-acc7-5bb723c74f47"  
}
 

Building PTB data

Building the transaction raw data from scratch can be challenging. The models Fordefi uses for the inputs, commands and gas_config are based on the TransactionBlock model in the@mysten/sui.js project.

The following example shows how to extract the rawInputs, rawCommands and rawGasConfig that should be converted to the API's standard (example):

const tx = new TransactionBlock();

tx.setSender('0x99746ebdb6813cefcc8d619edf7da78339933da7dab08e8792490d3a26f8f606');
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 rawInputs = tx.blockData.inputs;
const rawCommands = tx.blockData.transactions;
const rawGasConfig = tx.blockData.gasConfig;