# SUI object merging and split problem

**URL:** <https://forums.sui.io/t/sui-object-merging-and-split-problem/49039>\
**Category:** General\
**Created:** [August 19, 2025, 6:56am UTC](https://forums.sui.io/t/sui-object-merging-and-split-problem/49039 "2025-08-19T06:56:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndev.cc](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/ndev.cc/32/31568_2.png) [@ndev.cc](https://forums.sui.io/u/ndev.cc)\
**Post date:** [August 19, 2025, 6:56am UTC](https://forums.sui.io/t/sui-object-merging-and-split-problem/49039/1 "2025-08-19T06:56:05Z")

</div>

Hello. I have problem with SUI objects.  
Balance - 0.19 SUI 0x4805998aec408aaea27fda52be120d798b7ec79e0eb59fa2392cd1ba2f53dace (i can’t send links because forum doesnt allowing it, but i’ll leave address here)

My script getting objects of coin and merging or use single object before transaction  
It got  
`Using single coin: 0xbf71417931c5f4cc98a97dbe98844f584d14bc8e5850971c56f519fbbde2b505`

It got right object with 0.19 SUI - 0xbf71417931c5f4cc98a97dbe98844f584d14bc8e5850971c56f519fbbde2b505  
But if i try to send 0.002 SUI, it returns  
`Send token error: Total gas available 2185532, transaction requires 3464000`

Why? I not sending full balance, why i dont have enough gas

My code here:  
`async def send\_token(self, \*, to\_address: str | Wallet, coin\_type: str, amount: float):  
“”“Send token to a specific wallet”“”  
try:  
if isinstance(to\_address, Wallet):  
to\_address = str(to\_address.address)  
metadata = await self.cs.get\_coin\_metadata(coin\_type)  
amount = convert\_amount(amount, metadata.decimals)

```
    log.info(f"Sending {amount} {metadata.symbol} to {to_address}")

    coins = await self.cs.get_coin_objects(self.address, coin_type)

    if not coin_type:
        raise Exception(f"No tokens found for type {coin_type}")

    selected_coins, is_enough = calculate_coins(amount, coins)
    if not is_enough:
        raise Exception("Not enough tokens")

    txn: AsyncSuiTransaction = self.client.transaction(
        client=self.client, initial_sender=self.address
    )

    primary_coin_id = selected_coins[0].coin_object_id

    if len(selected_coins) == 1:
        log.info(f"Using single coin: {primary_coin_id}")
        scres = await txn.split_coin(coin=primary_coin_id, amounts=[amount])
    else:
        log.info(
            f"Merging {len(selected_coins)} of {len(coins)}... in {primary_coin_id}"
        )
        coins_to_merge = [coin.coin_object_id for coin in selected_coins[1:]]
        await txn.merge_coins(
            merge_to=primary_coin_id, merge_from=coins_to_merge
        )
        scres = await txn.split_coin(coin=primary_coin_id, amounts=[amount])

    await txn.transfer_objects(
        transfers=scres if isinstance(scres, list) else [scres], # type: ignore
        recipient=to_address,
    )

    txn_dict = await txn.build_and_sign()
    result = await self.client.execute_query_node(
        with_node=qn.ExecuteTransaction(**txn_dict)
    )

    if result.is_ok():
        await self.client.wait_for_transaction(digest=result.result_data.digest)
        log.success(f"Token transfer successful: {result.result_data.digest}")
        return result.result_data.digest
    else:
        log.error(f"Token transfer failed: {result.result_string}")
        raise Exception(result.result_string)

except Exception as e:
    log.error(f"Send token error: {str(e)}")
    raise e

```

async def send\_sui(self, to\_address: str | Wallet, amount: float) → str:  
“”“Send SUI to a specific wallet”“”  
if isinstance(to\_address, Wallet):  
to\_address = str(to\_address.address)  
return await self.send\_token(  
to\_address=to\_address, coin\_type=“0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI”, amount=amount  
)`

# Calculate coins func:

def calculate\_coins(amount: int, coins: list[Any]) → Tuple[list[Any], bool]:

```auto
sorted_coins = sorted(coins, key=lambda x: int(x.balance), reverse=True)

total_balance = 0
selected_coins = []

for coin in sorted_coins:
    selected_coins.append(coin)
    total_balance += int(coin.balance)

    if total_balance >= amount:
        break

```

1. Get all token objects
2. calculate\_coins func (for calculate how many objects we need to get needed amount)
3. Merge and send  
It’s simple. But it’s dont work (

Please help me.

Also i would like to know how to debug it, because i can’t get full error log in pysui 😅
