# Doing splitcoin and smart contact function call on the same transaction

**URL:** <https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600>\
**Category:** Technical Support\
**Created:** [May 19, 2024, 4:15pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600 "2024-05-19T16:15:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tahlil](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/tahlil/32/30688_2.png) [@tahlil](https://forums.sui.io/u/tahlil)\
**Post date:** [May 19, 2024, 4:15pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/1 "2024-05-19T16:15:59Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![tahlil](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/tahlil/32/30688_2.png) [@tahlil](https://forums.sui.io/u/tahlil)\
**Post date:** [May 19, 2024, 5:39pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/3 "2024-05-19T17:39:46Z")

</div>

@Soul812 no, not yet

---

<div class="post-metadata">

**Author:** ![fastfrank](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/fastfrank/32/1138_2.png) [@fastfrank](https://forums.sui.io/u/fastfrank)\
**Post date:** [May 21, 2024, 8:38am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/5 "2024-05-21T08:38:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tahlil](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/tahlil/32/30688_2.png) [@tahlil](https://forums.sui.io/u/tahlil)\
**Post date:** [May 21, 2024, 8:49am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/6 "2024-05-21T08:49:53Z")

</div>

@fastfrank

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

---

<div class="post-metadata">

**Author:** ![fastfrank](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/fastfrank/32/1138_2.png) [@fastfrank](https://forums.sui.io/u/fastfrank)\
**Post date:** [May 21, 2024, 8:56am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/7 "2024-05-21T08:56:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tahlil](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/tahlil/32/30688_2.png) [@tahlil](https://forums.sui.io/u/tahlil)\
**Post date:** [May 21, 2024, 9:03am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/8 "2024-05-21T09:03:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fastfrank](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/fastfrank/32/1138_2.png) [@fastfrank](https://forums.sui.io/u/fastfrank)\
**Post date:** [May 21, 2024, 12:37pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/9 "2024-05-21T12:37:04Z")

</div>

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)

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

```

---

<div class="post-metadata">

**Author:** ![fastfrank](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/fastfrank/32/1138_2.png) [@fastfrank](https://forums.sui.io/u/fastfrank)\
**Post date:** [May 23, 2024, 9:57am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/10 "2024-05-23T09:57:36Z")

</div>

Did you get it working?

---

<div class="post-metadata">

**Author:** ![tood](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tood](https://forums.sui.io/u/tood)\
**Post date:** [October 21, 2024, 2:59pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/11 "2024-10-21T14:59:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thebishalniroula](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/thebishalniroula/32/30824_2.png) [@thebishalniroula](https://forums.sui.io/u/thebishalniroula)\
**Post date:** [October 21, 2024, 5:33pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/12 "2024-10-21T17:33:21Z")

</div>

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,

```auto
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?

---

<div class="post-metadata">

**Author:** ![fastfrank](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/fastfrank/32/1138_2.png) [@fastfrank](https://forums.sui.io/u/fastfrank)\
**Post date:** [October 21, 2024, 7:25pm UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/13 "2024-10-21T19:25:06Z")

</div>

Using this reference [Building Programmable Transaction Blocks | Sui Documentation](https://docs.sui.io/guides/developer/sui-101/building-ptb)

Try it in devnet

---

<div class="post-metadata">

**Author:** ![tood](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tood](https://forums.sui.io/u/tood)\
**Post date:** [October 23, 2024, 3:49am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/14 "2024-10-23T03:49:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tood](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tood](https://forums.sui.io/u/tood)\
**Post date:** [October 23, 2024, 3:52am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/15 "2024-10-23T03:52:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tood](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@tood](https://forums.sui.io/u/tood)\
**Post date:** [October 23, 2024, 4:33am UTC](https://forums.sui.io/t/doing-splitcoin-and-smart-contact-function-call-on-the-same-transaction/45600/16 "2024-10-23T04:33:26Z")

</div>

hey bro, have you found a solution?
