Skip to content

Instantly share code, notes, and snippets.

@JackyWYX
Last active July 11, 2023 00:45
Show Gist options
  • Save JackyWYX/a13ab6353f6edbe6e8d769e070bf7818 to your computer and use it in GitHub Desktop.
Save JackyWYX/a13ab6353f6edbe6e8d769e070bf7818 to your computer and use it in GitHub Desktop.
// Build initial transaction block
const builder = new CoinTransferBuilder(mavenInfo.mavenId, mavenAccount.globals, {
coinType: SUI_COIN,
to: receiver,
amount: MIST_PER_SUI,
});
const tb = await builder.createTransactionBlock();
// Add to propose session and simulate
const session = await mavenAccount.proposeTransaction(tb);
const simulationResult = await session.simulate();
if (!simulationResult.success) {
// Display simulation error
}
// Set the gas cost. We can currently hard code the value to 120%. We can allow user to change later.
const gasFeeUsed = simulationResult.gasCost * 120n / 100n;
// Transfer the gas coin from user wallet to the maven account. This will open a window in wallet extension for user to sign.
const transferGasResponse = await session.transferGasObject(gasFeeUsed);
if (!transferGasResponse.effects || transferGasResponse.effects?.status.status !== 'success') {
// Display error.
}
// Finally, submit the proposed transaction to the backend
await session.propose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment