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.

@Soul812 no, not yet

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.

@fastfrank

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

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.

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

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({...})

Did you get it working?