Skip to content

How to merge and transfer 2k sui coin objects #18254

Answered by igdeman
igdeman asked this question in Q&A
Discussion options

You must be logged in to vote

I have come up with a solution, but I'm not sure if it is optimal:

it("Testing Transfer All Coins", async () => {
    const coins = await getCoins(sender.getPublicKey().toSuiAddress(), client);
    const gasCoins = coins.splice(0, Math.min(50, coins.length));
    const transferCoins: CoinStruct[] = [];

    const tx = new Transaction();
    tx.setSender(sender.getPublicKey().toSuiAddress());
    while (coins.length > 0) {
      const chunk = coins.splice(0, Math.min(512, coins.length));
      const [mergedCoin] = chunk.splice(0, 1);
      if (chunk.length > 0) tx.mergeCoins(mergedCoin.coinObjectId, chunk.map(coin => coin.coinObjectId));
      transferCoins.push(mergedCoin);
    }
    tx.s…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by igdeman
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants