Writing script for transactions thru Aptos bridge from BSC Chain. The problem is - every time I get the same transaction revert reason. LzApp: Not enough native token. I checked everything in aptos docs. Everything seems to be right but still nothing works
web3.eth.getTransactionCount(fromAddress).then((nonce) => {
const approveTxData = tokenContract.methods.approve(tokenBridgeAddress, amountLD).encodeABI();
const approveTransaction = {
to: usddTokenAddress,
data: approveTxData,
gas: 100000,
nonce: nonce,
};
web3.eth.accounts.signTransaction(approveTransaction, privateKey).then((signedApproveTx) => {
web3.eth.sendSignedTransaction(signedApproveTx.rawTransaction).on('receipt', (approveReceipt) => {
console.log('Approve receipt:', approveReceipt);
const callParams = {
refundAddress: fromAddress,
zroPaymentAddress: zroPaymentAddress
};
const adapterParams = ethers.utils.solidityPack(
['uint16', 'uint256'],
[1, 300000]
);
console.log('AdapterParams:', adapterParams);
const dstChainId = 108;
const userApplication = fromAddress;
const payload = '0x'
const payInZRO = false; //
endpointContract.methods.estimateFees(dstChainId, userApplication, payload, payInZRO, adapterParams).call()
.then(fees => {
console.log('Fees (Native):', fees.nativeFee, 'wei');
console.log('Fees (ZRO):', fees.zroFee, 'wei');
const totalFee = BigInt(fees.nativeFee) + BigInt(fees.zroFee);
console.log('Total fees:', totalFee.toString(), 'wei');
web3.eth.getTransactionCount(fromAddress).then((nonce) => {
const txData = tokenBridgeContract.methods.sendToAptos(usddTokenAddress, toAddress, amountLD, callParams, adapterParams).encodeABI();
const transaction = {
to: tokenBridgeAddress,
data: txData,
gas: 300000,
nonce: nonce,
value: fees.totalFee
};
web3.eth.accounts.signTransaction(transaction, privateKey).then((signedTx) => {
web3.eth.sendSignedTransaction(signedTx.rawTransaction).on('receipt', console.log).on('error', console.error);
}).catch(console.error);
});
})
.catch(console.error);
}).on('error', console.error);
});
});
I tried different ways to estimate fees. Play with adapter parameters, gave wei price, native price, total price. I really stucked