sui_jsonrpc/api/
transaction_builder.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3#![allow(clippy::too_many_arguments)]
4
5use jsonrpsee::proc_macros::rpc;
6use sui_sdk_types::Address;
7
8use crate::msgs::{
9    RPCTransactionRequestParams,
10    SuiTransactionBlockBuilderMode,
11    SuiTypeTag,
12    TransactionBlockBytes,
13};
14use crate::serde::BigInt;
15
16#[rpc(client, namespace = "unsafe")]
17pub trait TransactionBuilder {
18    /// Create an unsigned transaction to transfer an object from one address to another. The object's type
19    /// must allow public transfers
20    #[method(name = "transferObject")]
21    async fn transfer_object(
22        &self,
23        signer: Address,
24        object_id: Address,
25        gas: Option<Address>,
26        gas_budget: BigInt<u64>,
27        recipient: Address,
28    ) -> RpcResult<TransactionBlockBytes>;
29
30    /// Create an unsigned transaction to send SUI coin object to a Sui address. The SUI object is also used as the gas object.
31    #[method(name = "transferSui")]
32    async fn transfer_sui(
33        &self,
34        signer: Address,
35        sui_object_id: Address,
36        gas_budget: BigInt<u64>,
37        recipient: Address,
38        amount: Option<BigInt<u64>>,
39    ) -> RpcResult<TransactionBlockBytes>;
40
41    /// Send `Coin<T>` to a list of addresses, where `T` can be any coin type, following a list of amounts,
42    /// The object specified in the `gas` field will be used to pay the gas fee for the transaction.
43    /// The gas object can not appear in `input_coins`. If the gas object is not specified, the RPC server
44    /// will auto-select one.
45    #[method(name = "pay")]
46    async fn pay(
47        &self,
48        signer: Address,
49        input_coins: Vec<Address>,
50        recipients: Vec<Address>,
51        amounts: Vec<BigInt<u64>>,
52        gas: Option<Address>,
53        gas_budget: BigInt<u64>,
54    ) -> RpcResult<TransactionBlockBytes>;
55
56    /// Send SUI coins to a list of addresses, following a list of amounts.
57    /// This is for SUI coin only and does not require a separate gas coin object.
58    /// Specifically, what pay_sui does are:
59    /// 1. debit each input_coin to create new coin following the order of
60    /// amounts and assign it to the corresponding recipient.
61    /// 2. accumulate all residual SUI from input coins left and deposit all SUI to the first
62    /// input coin, then use the first input coin as the gas coin object.
63    /// 3. the balance of the first input coin after tx is sum(input_coins) - sum(amounts) - actual_gas_cost
64    /// 4. all other input coints other than the first one are deleted.
65    #[method(name = "paySui")]
66    async fn pay_sui(
67        &self,
68        signer: Address,
69        input_coins: Vec<Address>,
70        recipients: Vec<Address>,
71        amounts: Vec<BigInt<u64>>,
72        gas_budget: BigInt<u64>,
73    ) -> RpcResult<TransactionBlockBytes>;
74
75    /// Send all SUI coins to one recipient.
76    /// This is for SUI coin only and does not require a separate gas coin object.
77    /// Specifically, what pay_all_sui does are:
78    /// 1. accumulate all SUI from input coins and deposit all SUI to the first input coin
79    /// 2. transfer the updated first coin to the recipient and also use this first coin as gas coin object.
80    /// 3. the balance of the first input coin after tx is sum(input_coins) - actual_gas_cost.
81    /// 4. all other input coins other than the first are deleted.
82    #[method(name = "payAllSui")]
83    async fn pay_all_sui(
84        &self,
85        signer: Address,
86        input_coins: Vec<Address>,
87        recipient: Address,
88        gas_budget: BigInt<u64>,
89    ) -> RpcResult<TransactionBlockBytes>;
90
91    /// Create an unsigned transaction to execute a Move call on the network, by calling the specified function in the module of a given package.
92    #[method(name = "moveCall")]
93    async fn move_call(
94        &self,
95        signer: Address,
96        package_object_id: Address,
97        module: String,
98        function: String,
99        type_arguments: Vec<SuiTypeTag>,
100        arguments: Vec<serde_json::Value>,
101        gas: Option<Address>,
102        gas_budget: BigInt<u64>,
103        execution_mode: Option<SuiTransactionBlockBuilderMode>,
104    ) -> RpcResult<TransactionBlockBytes>;
105
106    /// Create an unsigned transaction to publish a Move package.
107    #[method(name = "publish")]
108    async fn publish(
109        &self,
110        sender: Address,
111        compiled_modules: Vec<String>,
112        dependencies: Vec<Address>,
113        gas: Option<Address>,
114        gas_budget: BigInt<u64>,
115    ) -> RpcResult<TransactionBlockBytes>;
116
117    /// Create an unsigned transaction to split a coin object into multiple coins.
118    #[method(name = "splitCoin")]
119    async fn split_coin(
120        &self,
121        signer: Address,
122        coin_object_id: Address,
123        split_amounts: Vec<BigInt<u64>>,
124        gas: Option<Address>,
125        gas_budget: BigInt<u64>,
126    ) -> RpcResult<TransactionBlockBytes>;
127
128    /// Create an unsigned transaction to split a coin object into multiple equal-size coins.
129    #[method(name = "splitCoinEqual")]
130    async fn split_coin_equal(
131        &self,
132        signer: Address,
133        coin_object_id: Address,
134        split_count: BigInt<u64>,
135        gas: Option<Address>,
136        gas_budget: BigInt<u64>,
137    ) -> RpcResult<TransactionBlockBytes>;
138
139    /// Create an unsigned transaction to merge multiple coins into one coin.
140    #[method(name = "mergeCoins")]
141    async fn merge_coin(
142        &self,
143        signer: Address,
144        primary_coin: Address,
145        coin_to_merge: Address,
146        gas: Option<Address>,
147        gas_budget: BigInt<u64>,
148    ) -> RpcResult<TransactionBlockBytes>;
149
150    /// Create an unsigned batched transaction.
151    #[method(name = "batchTransaction")]
152    async fn batch_transaction(
153        &self,
154        signer: Address,
155        single_transaction_params: Vec<RPCTransactionRequestParams>,
156        gas: Option<Address>,
157        gas_budget: BigInt<u64>,
158        txn_builder_mode: Option<SuiTransactionBlockBuilderMode>,
159    ) -> RpcResult<TransactionBlockBytes>;
160
161    /// Add stake to a validator's staking pool using multiple coins and amount.
162    #[method(name = "requestAddStake")]
163    async fn request_add_stake(
164        &self,
165        signer: Address,
166        coins: Vec<Address>,
167        amount: Option<BigInt<u64>>,
168        validator: Address,
169        gas: Option<Address>,
170        gas_budget: BigInt<u64>,
171    ) -> RpcResult<TransactionBlockBytes>;
172
173    /// Withdraw stake from a validator's staking pool.
174    #[method(name = "requestWithdrawStake")]
175    async fn request_withdraw_stake(
176        &self,
177        signer: Address,
178        staked_sui: Address,
179        gas: Option<Address>,
180        gas_budget: BigInt<u64>,
181    ) -> RpcResult<TransactionBlockBytes>;
182}