记录一些会经常用到的代码段
记录一些会经常用到的代码段/方法,会持续更新...
// 要分隔的数量 精度
const suiAmount = 1 * 10 ** Sui.decimal;
// 分隔
const [suiCoin] = tx.splitCoins(tx.gas, [suiAmount]);
// 合并 coin
tx.mergeCoins(tx.object(coinObjectId), [tx.object(coinObjectId_2), tx.object(coinObjectId_3)]);
// 定义钩子函数
const { mutate: signAndExecuteTransaction } = useSignAndExecuteTransaction();
// 执行交易
signAndExecuteTransaction({
transaction: tx,
}, {
onSuccess: (result) => {
console.log(result.digest);
},
onError: (error) => {
console.log(error);
}
});
}
// moveCall 传参
const claimFunctionWithTypeArgs = async () => {
const tx = new Transaction();
await tx.moveCall({
package: "0x9added62ef3a869653ef13e754d51fb62adc9f93e2717d2e23ba1214c4ef8d15",
module: "distributor",
function: "claim_rewards",
typeArguments: [ '0xe1b45a0e641b9955a20aa0ad1c1f4ad86aad8afb07296d4085e349a50e90bdca::blue::BLUE',
],
arguments: [
tx.pure.string("0x0000000000000000000000000000000000000000000000000000000000000006"),
tx.pure.vector("u8", [4, 0, 1]),
]
});
signAndExecuteTransaction({
transaction: tx,
}, {
onSuccess: (result) => {
console.log(result.digest);
},
onError: (error) => {
console.log(error);
}
});
}
const handleLoadEvens = async () => {
const events = await suiClient.queryEvents({
query: {
MoveEventType: "0x914099b4d1b4f5513acc8aaa4fdc1f67578522b81d818f61bae527d590c6d87d::check_in::Flag",
}
});
console.log(events.data);
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!