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
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
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
tood
October 21, 2024, 2:59pm
11
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
tood
October 23, 2024, 3:49am
14
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
tood
October 23, 2024, 3:52am
15
not transactionBlock, because sdk was update,all trsblock to transaction
1 Like
tood
October 23, 2024, 4:33am
16
hey bro, have you found a solution?
1 Like