Sign and Submit Transaction
And you can integrate more things or your D.app features with Transactionsmethods
1.1. Single signer transaction
payload = {
"type": "entry_function_payload",
"function": "0x1::coin::transfer",
"type_arguments": ["0x1::aptos_coin::AptosCoin"],
"arguments": [
"0x...", // recipient adddress
"1000", // amount of APT - decimals = 8
]
}
rawTransaction = (await fewcha.aptos.generateTransaction(payload)).data;
// Simulate transaction before submission (Optional)
simulateRes = (await fewcha.simulateTransaction(rawTransaction)).data;
// Sign then submit
signedTx = (await fewcha.signTransaction(rawTransaction)).data;
txHash = (await fewcha.aptos.submitTransaction(signedTx)).data;
// Or Sign and submit
txHash = (await fewcha.aptos.signAndSubmitTransaction(rawTransaction)).data;
1.2. Multiple agent transaction
payload = {
"type": "entry_function_payload",
"function": "0x3::token::direct_transfer_script",
"type_arguments": [],
"arguments": [
"0x...", // creator address
"Fewcha Membership", // token collection
"Member Level 1", // token name
"0", // property_version
"1", // amount of token
]
}
// List of secondary addresses
// direct_transfer_script
// 2 signers is required (primary and 1 secondary signer)
secondarySigners = [
"0x...",
]
options = {
// Primary signer
// If not specified, the current connected account will be selected
"sender": "0x..."
// Other options...
}
rawMultiAgentTransaction = (await
fewcha.aptos.generateMultiAgentTransaction(
payload,
secondarySigners,
options
)
).data;
2. Get signatures
primaryPubKey = (await fewcha.account()).data.publicKey;
primarySignedTx = (await
fewcha.aptos.signMultiAgentTransaction(
rawMultiAgentTransaction
)
).data;
// Change account to the secondary signers specified from the transaction generation step
secondaryPubKey = (await fewcha.account()).data.publicKey;
secondarySignedTx = (await
fewcha.aptos.signMultiAgentTransaction(
rawMultiAgentTransaction
)
).data;
3. Submit (or simulate) transaction
// Simulate
simulateRes = (await fewcha.aptos.simulateMultiAgentTransaction(
rawMultiAgentTransaction, // multiAgentTxn
[options.sender, ...secondarySigners], // addresses
[primaryPubKey, secondaryPubKey], // pubKeys
)).data;
// Submit
txnHash = (await fewcha.aptos.submitSignedBCSMultiAgentTransaction(
rawMultiAgentTransaction, // multiAgentTxn
[options.sender, ...secondarySigners], // addresses
[primaryPubKey, secondaryPubKey], // pubKeys
[primarySignedTx, secondarySignedTx] // signatures
)).data;
1.3. Multiple signature transaction
Collection account public keys and generate multi-sign address
firstPubKey = (await fewcha.account()).data.publicKey;
secondPubKey = (await fewcha.account()).data.publicKey;
thirdPubKey = (await fewcha.account()).data.publicKey;
const {address, publicKey} = (await fewcha.aptos.getMultiSignAccount(
[firstPubKey, secondPubKey, thirdPubKey], // list signer publicKeys
2 // threshold - the number of signature made the transaction valid
)).data;
payload = {
"type": "entry_function_payload",
"function": "0x1::coin::transfer",
"type_arguments": ["0x1::aptos_coin::AptosCoin"],
"arguments": [
"0x...", // recipient adddress
"1000", // amount of APT - decimals = 8
]
}
options = {
// Multi-sign address
"sender": "0x..."
// Other options...
}
rawTransaction = (await
fewcha.aptos.generateTransaction(
payload,
options
)
).data;
3. Get at least threshold signatures from the list signers
firstSignature = (await fewcha.aptos.signMultiSignTransaction(rawTransaction)).data;
thirdSignature = (await fewcha.aptos.signMultiSignTransaction(rawTransaction)).data;
4. Submit (or simulate) transaction
// Simulate transaction before submission (Optional)
simulateRes = (await fewcha.simulateTransaction(rawTransaction)).data;
txnHash = (await fewcha.aptos.submitSignedBCSMultiSignTransaction(
rawTransaction, // Transaction
[0,2], // Bitmap - 0 is index of first signer, 2 is index of third signer
publicKey, // multi-sign public key we got from step 1
[firstSignature, thirdSignature]
)).data;
Construct transaction payload
payload = {
suiObjectId: "0x...",
gasBudget: 1000,
recipient: "0x...",
amount: 1000
}
2. Submit the transaction
response = (await fewcha.sui.transferSui(payload)).data
Last updated