Last active
July 11, 2023 00:45
-
-
Save JackyWYX/a13ab6353f6edbe6e8d769e070bf7818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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