There is enough balance, the network is also working correctly, the keys are also correct, the gas has been increased, but the error remains.
const ethers = require("ethers");
const networkRPC = 'https://eth-sepolia.g.alchemy.com/v2/UfPvcFpj2bEwwTF4OXlEVP4atqGHfgUk';
const senderPrivateKey = '0xa0278f908d619f8967aa252b80679ca5ff2e85b31103dd53741c39780f6717a3';
const recipientAddress = '0xa014da1d3baC8799E78EE5cF87ff2bb105491d28';
const tokenAddress = '0x91B25A65b295F0405552A4bbB77879ab5e38166c';
const amountToSend = "0.000001"; // Указывайте в токенах, которые будут конвертированы в Wei
const provider = new ethers.providers.JsonRpcProvider(networkRPC);
const senderWallet = new ethers.Wallet(senderPrivateKey, provider);
const tokenABI = [
"function balanceOf(address owner) view returns (uint256)",
"function transfer(address to, uint amount) returns (bool)"
];
const tokenContract = new ethers.Contract(tokenAddress, tokenABI, senderWallet);
async function sendSWAN() {
try {
const amountInWei = ethers.utils.parseUnits(amountToSend, 18);
// Проверка баланса перед отправкой
const senderBalance = await tokenContract.balanceOf(senderWallet.address);
if (senderBalance.lt(amountInWei)) {
console.error("Недостаточно средств для отправки");
return;
}
// Фиксированные значения газа и цены газа
const gasLimit = ethers.BigNumber.from("2100000");
const gasPrice = ethers.BigNumber.from("8000000000");
// Отправка транзакции
const transaction = await tokenContract.transfer(recipientAddress, amountInWei, {
gasLimit: gasLimit,
gasPrice: gasPrice
});
console.log(`Транзакция отправлена: ${transaction.hash}`);
const receipt = await transaction.wait();
console.log(`Транзакция успешно выполнена в блоке ${receipt.blockNumber}`);
} catch (error) {
console.error(`Ошибка при отправке транзакции: ${error.message}`);
}
}
sendSWAN().catch(console.error);
tokenABIvalue that you're using, is not applicable for this, so you cannot call the correspondingbalanceOf()andtransfer()functions for this token. – SYED ASAD KAZMI Mar 17 '24 at 09:14