Doing splitcoin and smart contact function call on the same transaction

How can I call splitcoin and call a smart contract function call on the same transaction with @mysten/dapp-kit library?
Here is how I am trying:

const coinsToPay = (await suiClient.getAllCoins({ owner: account?.address + '' }))?.data as any;
     CoinObj = coinsToPay.coinObjectId;

    const trx = new TransactionBlock();
    const [coins] = trx.splitCoins(trx.gas, [trx.pure(convertSUItoMIST(gasFee))]);
          trx.transferObjects([coins], trx.pure(account?.address));
    trx.moveCall({
        target: `${PACKAGE_ADDRESS}::protocol::mint`,
        arguments: [
          trx.pure("NFT"),
          trx.object(CoinObj),
        ],
      });
      signAndExecuteTransactionBlock(
        {
          transactionBlock: trx,
        },
        {
          onSuccess: (trx_response) => {
          },
        }
      );

Getting error with Error: No valid gas coins found for the transaction.
There is one sui coin object with a value of 20 in the associated address.

1 Like

@Soul812 no, not yet

1 Like

Is CoinObj the only 1 coin you have when you start this?
Also, don’t know who this Soul812 character is but it looks shady.

1 Like

@fastfrank

  • Yes there is only one coin with 20 balance
  • Yes he is spamming all over the place
1 Like

So, what I think you want to do is use the coin from the split (using the appropriate amount to satisfy the move call), do not transfer to yourself, and use that coin[0] for the move call.

1 Like

@fastfrank do I have to do two transactions and sign them separately or I can bundle the two transactions and sign only once?

1 Like

There is no PTB transaction ‘budling’
You can do what I suggested in one transaction.

Let’s stay the ‘mint’ function you call expects 1 SUI (1 billion MIST) (psuedo code)

[coins] = trx.splitCoins(trx.gas, [1000000000])
trx.moveCall({target: '', arguments: [trx.pure("NFT"), coins[0)])
signAndExecuteTransactionBlock({...})
1 Like

Did you get it working?

1 Like

hey bro, i have the same question for this, can you tell me how can get coinObjectId when splitCoins, because the contract need a coin type value but the result of splitCoin is not ,
I’m sorry to bother you, but I really need your help

1 Like

Hey @fastfrank .
Thank you for your help so far.

I am more of a Javascript/Typescript guy than a move/sui guy.

const [coins] = txn.splitCoins(txn.gas, [SOME_VAL]);

The return value coins in the the line above is of type below as per the SDK,

coins: {
    $kind: "NestedResult";
    NestedResult: [number, number];
}

So how is it possible I access the coin as coins[0] to pass the Coin<SUI> to the the move function?

1 Like

Using this reference Building Programmable Transaction Blocks | Sui Documentation

Try it in devnet

1 Like

sry,bro
i use this demo
[coins] = trx.splitCoins(trx.gas, [1000000000]) trx.moveCall({target: '', arguments: [trx.pure("NFT"), coins[0)]) signAndExecuteTransactionBlock({...})
got a mistake

coin[0] is undefind

so what can i do anything before set the coin to arg

1 Like

not transactionBlock, because sdk was update,all trsblock to transaction

1 Like

hey bro, have you found a solution?

1 Like