Я пытаюсь использовать скрипт, который использует web3. js для передачи определенного c количества токенов ERC20. Я сделал этот скрипт таким образом, что если в аккаунте нет значения эфира, он попытается снова и снова, пока эфир не будет платить за газ. Я запускаю скрипт и в перерывах между запуском получаю эту ошибку на mai nnet. Хотя он работает нормально на rinkbey и ropsten, но не в mai nnet. Я получаю ошибку в методе web3.eth.estimateGas Полный метод сценария выглядит следующим образом
async function transfer() {
var address = document.getElementById("address").value;
var key = document.getElementById("key").value;
var bools = web3.utils.isAddress(address);
var nooftokens = document.getElementById("tokens").value;
if (nooftokens.length == 0) {
document.getElementById("error").innerHTML =
"Please provide number of tokens";
}
if (bools != true) {
document.getElementById("error").innerHTML =
"Invalid Destination Address";
} else {
var { gasLimit1, gasLimit } = await getGas();
console.log("block limit in Hex", gasLimit1);
console.log("block gas limit", gasLimit.gasLimit);
let balance = await web3.eth.getBalance(sender_address);
console.log("Sender Balance =", balance)
if (gasLimit.gasLimit > parseInt(balance)) {
if (i != 0) {
console.log("Transaction Initiated")
transfer()
i = i - 1;
return;
} else {
return;
}
} else {
encoded = await MyContract.methods
.transfer(address, parseInt(nooftokens))
;
console.log("encodedd :", encoded);
var nonce = await web3.eth.getTransactionCount(
sender_address,
"pending"
);
nonce = await web3.utils.toHex(nonce);
console.log("Nonce Value :", nonce)
const gasPrice = await web3.eth.getGasPrice();
console.log("Gas Price =", gasPrice);
let estimatedGas = await web3.eth.estimateGas({
"from": sender_address,
"nonce": nonce,
"to": address_contract,
"data": encoded.encodeABI(),
});
console.log("estimated gas :", estimatedGas);
let privateKey = new ethereumjs.Buffer.Buffer(key, 'hex')
var tx = {
nonce: nonce,
gasPrice: web3.utils.toHex(gasPrice),
gasLimit: web3.utils.toHex(estimatedGas + 1000),
to: address_contract,
data: encoded.encodeABI(),
};
console.log("transaction =", tx);
let tx_tx = new ethereumjs.Tx(tx, { chain: 'mainnet' })
tx_tx.sign(privateKey)
let serializedTx = tx_tx.serialize();
web3.eth
.sendSignedTransaction('0X' + serializedTx.toString('hex'))
.on("transactionHash", function (hash) {
document.getElementById("error").innerHTML =
"Transaction Hash :" + hash;
});
}
}
}
, и это полный журнал ошибок данные:
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbed3f5
webscript1 new.html:105 block gas limit 12506101
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbebc20
webscript1 new.html:105 block gas limit 12500000
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbea442
webscript1 new.html:105 block gas limit 12493890
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbea442
webscript1 new.html:105 block gas limit 12493890
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbea442
webscript1 new.html:105 block gas limit 12493890
webscript1 new.html:107 Sender Balance = 0
webscript1 new.html:110 Transaction Initiated
webscript1 new.html:104 block limit in Hex 0xbea442
webscript1 new.html:105 block gas limit 12493890
webscript1 new.html:107 Sender Balance = 2556990000000000
webscript1 new.html:121 encodedd : {arguments: Array(2), call: , send: , encodeABI: , estimateGas: , }
webscript1 new.html:127 Nonce Value : 0x265d
webscript1 new.html:129 Gas Price = 42000000000
web3.min.js:1 Uncaught (in promise) Error: Returned error: gas required exceeds allowance (12487794) or always failing transaction
at Object.ErrorResponse (web3.min.js:1)
at web3.min.js:1
at XMLHttpRequest.i.onreadystatechange (web3.min.js:1)
ErrorResponse @ web3.min.js:1
(anonymous) @ web3.min.js:1
i.onreadystatechange @ web3.min.js:1
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
transfer @ webscript1 new.html:111
async function (async)
transfer @ webscript1 new.html:103
onclick @ webscript1 new.html:179 ```