Getting INSUFFICIENT_BALANCE_FOR_TRANSACTION_FEE
#45
-
Asked by const aptosConfig = new Aptos.AptosConfig({ network: Aptos.Network.MAINNET, fullnode: 'https://fullnode.mainnet.aptoslabs.com/v1' });
const aptos = new Aptos.Aptos(aptosConfig);
const privateKey = new Aptos.Ed25519PrivateKey(aptosPrivateKey);
const accountAddress = Aptos.AccountAddress.from(aptosAddress);
const account = Aptos.Account.fromPrivateKey({ privateKey, address: accountAddress });
console.log(`Wallet: ${account.accountAddress}`)
const usdcBalance = await aptos.getAccountResource({
accountAddress: account.accountAddress,
resourceType: "0x1::coin::CoinStore<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC>",
});
const usdcBalanceVal = usdcBalance.coin.value;
const swapTransaction = await aptos.transaction.build.simple({
sender: account.accountAddress,
data: {
function: "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::swap",
typeArguments: ["0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC","0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::WETH","0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated"],
functionArguments: [usdcBalanceVal,0],
}
});
console.log(swapTransaction)
const senderAuthenticator = aptos.transaction.sign({
signer: account,
transaction: swapTransaction,
});
const committedTransaction = await aptos.transaction.submit.simple({
transaction: swapTransaction,
senderAuthenticator: senderAuthenticator,
}); |
Beta Was this translation helpful? Give feedback.
Answered by
gregnazario
Mar 8, 2024
Replies: 2 comments 7 replies
-
Running exact same code you provided, I can swap successfully. can you try printing your APT balance like this? const aptBalance = await aptos.getAccountResource({
accountAddress: account.accountAddress,
resourceType: `0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>`,
});
const aptBalanceVal = aptBalance.coin.value;
console.log(`APT Balance: ${aptBalanceVal}`); |
Beta Was this translation helpful? Give feedback.
3 replies
-
I am now having another issue. For a different function, I am passing hexstrings as parameters but they come out as completely different strings on the explorer and cause the tx to fail.
In this case,
but they come out as following on the failed transaction:
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, exactly. You will get
INSUFFICIENT_BALANCE_FOR_TRANSACTION_FEE
if yourMaxGasAmount * gas price > amount in wallet (and the transfer amount)
You can define it as