Toolkit for interacting with SUI network in typescript
Toolkit for interacting with SUI network in typescript
@mysten/sui is a peer dependency, so install it alongside sui-kit:
npm install @scallop-io/sui-kit @mysten/sui…You can use SuiKit to transfer SUI, custom coins, and any objects.
…You can use SuiKit to stake SUI.
/**
* This is an example of using SuiKit to stake SUI
*/
const stakeAmount = 1000;
const validatorAddress = '0x123'; // replace with real address
suiKit.stakeSui(stakeAmount, validatorAddress).then(() => {
console.log('Stake SUI success');
});You can use SuiKit to call move functions.
const res = await suiKit.moveCall({
target: '0x2::coin::join',
arguments: [coin0, coin1],
typeArguments: [coinType],
});
console.log(res);How to pass arguments? Suppose you have a move function like this:
public entry fun test_args(
addrs: vector,
name: vector,
numbers: vector,
bools: vector,
coins: vector>,
ctx: &mut TxContext,
) {
// ...
}You can pass the arguments like this:
…All the supported types are:
With programmable transaction, you can send a transaction with multiple actions. The following is an example using flashloan to make arbitrage. (check here for the corresponding Move contract code)
…TransactionSuiTxBlock extends Transaction from @mysten/sui, so every base method and
property is available directly on it — there is no wrapped .txBlock to reach
through.
const tx = new SuiTxBlock();
tx.setSender(sender);
const coin = tx.object('');
const [amount] = tx.splitCoins(tx.gas, [1000]);
const bytes = await tx.build({ client: suiKit.client });You can also copy or restore a transaction as a SuiTxBlock:
import { Transaction } from '@mysten/sui/transactions';
// copy an existing Transaction (or SuiTxBlock)
const copy = new SuiTxBlock(new Transaction());
// restore from `toJSON()` output or BCS transaction bytes
const restored = SuiTxBlock.from(await tx.toJSON());
// restore from transaction kind bytes
const kind = SuiTxBlock.fromKind(
await tx.build({ client: suiKit.client, onlyTransactionKind: true })
);The overridden helpers accept sui-kit's looser argument types, so object ids, object refs and shared object refs work anywhere an object is expected:
tx.splitCoins({ objectId: '', version: '1', digest: '' }, [1000]);
tx.mergeCoins('', ['', '']);
tx.transferObjects([''], recipient);Two differences from the base class to keep in mind:
moveCall takes positional arguments (target, args, typeArgs) as shown
above; the base { target, arguments, typeArguments } object form is not
accepted.moveCall narrows the base signature, TypeScript may require a cast
when passing a SuiTxBlock to an API typed as Transaction. SuiKit methods
such as signTxn, signAndSendTxn, dryRunTxn and inspectTxn accept it
directly.SuiKit follows bip32 & bip39 standard, so you can use it to manage multiple accounts. When init SuiKit, you can pass in your mnemonics to create a wallet with multiple accounts.
…We have a standalone npm package to help you publish and upgrade Move package based on sui-kit.
Please refer to the repository: sui-package-kit
If you're upgrading from v1.x to v2.0.0, please refer to the Migration Guide.
No open issues yet, or sync has not completed.