# Sending coin object as function parameter when there is only one coin object

**URL:** <https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506>\
**Category:** Technical Support\
**Tags:** sdk\
**Created:** [April 28, 2024, 1:13pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506 "2024-04-28T13:13:36Z")\
**Posts on this page:** 8\
**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:** [April 28, 2024, 1:13pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/1 "2024-04-28T13:13:36Z")

</div>

Using sui SDK in a react app, I want to call a function that takes a coin as an argument. Now the wallet I connected most of the time only has one coin object. Now if send the coin object as an argument I get an error probably because there is no gas object. Is there any syntax that the SDK would automatically handle the gas payment and still send the coin object? Since splitting the coin would prompt the wallet twice though (maybe sending two transactions and signing once might be a solution, but I am not sure the syntax allows this).

---

<div class="post-metadata">

**Author:** ![shb](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@shb](https://forums.sui.io/u/shb)\
**Post date:** [April 28, 2024, 9:17pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/2 "2024-04-28T21:17:25Z")

</div>

The easiest way to do this is to build a PTB that first splits off a piece of the (single) input gas coin with the value you want to send, and then transfers the piece. The code from [Building Programmable Transaction Blocks | Sui Documentation](https://docs.sui.io/guides/developer/sui-101/building-ptb) is a good reference for this:

```auto
const [coin] = txb.splitCoins(txb.gas, [txb.pure(100)]);
txb.transferObjects([coin], txb.pure("0xSomeSuiAddress"));

```

---

<div class="post-metadata">

**Author:** ![shb](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@shb](https://forums.sui.io/u/shb)\
**Post date:** [April 28, 2024, 9:35pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/3 "2024-04-28T21:35:15Z")

</div>

However, if your intention is to transfer the entire gas coin (not a specific amount), you would do something like

```auto
txb.transferObjects([txb.gas], txb.pure("0xSomeSuiAddress"));

```

---

<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:** [April 29, 2024, 7:03am UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/4 "2024-04-29T07:03:31Z")

</div>

@shb Thank you for the response. Two follow-up questions:

1. Is `0xSomeSuiAddress` referring to my own address? Cause I want to send the coin object in the function call later on like:

```auto
trx.moveCall({
        target: `${PACKAGE_ID}::protocol::mint`,
        arguments: [
          trx.pure(name),
          trx.object(coinObjectId),
        ],
      });

```

Here `coinObjectId` is the only coin object owned by the address.  
2. More importantly, if you think about this happening from the frontend’s perspective, if we do go for the split coin approach, the user has to sign twice - one for splitting the coin and two for signing the tx to use the splited coin object and execute the function from the Package. IN what approach we make this a single signing experience?

---

<div class="post-metadata">

**Author:** ![shb](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@shb](https://forums.sui.io/u/shb)\
**Post date:** [April 29, 2024, 3:10pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/5 "2024-04-29T15:10:46Z")

</div>

You can do something like

```auto
const [coin] = trx.splitCoins(txb.gas, [txb.pure(100)]);
trx.moveCall({
   target: `${PACKAGE_ID}::protocol::mint`,
        arguments: [
          trx.pure(name),
          coin,
        ],
});
signer.signAndExecuteTransactionBlock({ transactionBlock: trx });

```

This will not require the user to sign twice–the split, Move call, and any other commands you make will be packed into a single programmable transaction block that is signed once and executed atomically.

---

<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:** [April 30, 2024, 2:21pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/6 "2024-04-30T14:21:41Z")

</div>

@shb I am getting the following error:

```auto
Dry run failed, could not automatically determine a
 budget: UnusedValueWithoutDrop { result_idx: 0, secondary_idx: 0 } 
(code: -1)

```

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://forums.sui.io/u/stefan)\
**Post date:** [April 30, 2024, 6:46pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/7 "2024-04-30T18:46:56Z")

</div>

Not a Move expert, but this is what I think happens. After the move call, you need to do something with the new object that was minted - that’s what `UnusedValueWithoutDrop` tells you - you have an object that is not dropped but also not transferred to an address / another object. Likely, you want to transfer it to some address to hold it.

---

<div class="post-metadata">

**Author:** ![softtik](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@softtik](https://forums.sui.io/u/softtik)\
**Post date:** [June 11, 2024, 7:14pm UTC](https://forums.sui.io/t/sending-coin-object-as-function-parameter-when-there-is-only-one-coin-object/45506/8 "2024-06-11T19:14:18Z")

</div>

To perform this operation efficiently, you can use Programmable Transaction Blocks (PTBs) to split and transfer a portion of a gas coin. Here’s a concise explanation:

1. **Split the Coin** : Use `splitCoins` to isolate the specific value you want to send.
2. **Transfer the Coin** : Use `transferObjects` to send the split coin to the desired address.

Here’s a sample code snippet from the Sui Documentation:

```javascript
const [coin] = txb.splitCoins(txb.gas, [txb.pure(100)]);
txb.transferObjects([coin], txb.pure("0xSomeSuiAddress"));

```

In this example, `splitCoins` splits off 100 units of the gas coin, and `transferObjects` transfers it to the specified address. This method is efficient for managing and transferring digital assets, including NFTs  
. For more details, check the “Building Programmable Transaction Blocks” section in the Sui Documentation.
