I'm trying to send a transaction for a token with a locked contract. I'm doing this to find out when this contract will be open. So I'm expecting to get some kind of error like "ERC-20 Token Transfer Error (Unable to locate corresponding Transfer Event Logs), Check with Sender" or something, but I get this instead:
Error: insufficient funds for gas * price + value
I saw a lot of articles about this and tried everything, but everything leads to the same error. Is it even possible to make an app check whenever contract will be open? My code:
const main = async () => {
console.log(`web3 version: ${web3.version}`);
const myAddress = '0x...';
const destAddress = '0x...';
const transferAmount = 1;
const count = await web3.eth.getTransactionCount(myAddress);
console.log(`num transactions so far: ${count}`);
const abiArray = JSON.parse(fs.readFileSync(path.resolve(__dirname, './contract.json'), 'utf-8'));
const contractAddress = '0x...';
const contract = new web3.eth.Contract(abiArray, contractAddress, { from: myAddress });
const balance = await contract.methods.balanceOf(myAddress).call();
console.log(`Balance before send: ${balance}`);
const rawTransaction = {
'from': myAddress,
'nonce': '0x' + count.toString(16),
'gasPrice': '0x09184e72a000',
'gasLimit': '0x2710',
'to': contractAddress,
'value': '0x0',
'data': contract.methods.transfer(destAddress, transferAmount).encodeABI(),
'chainId': 0x01
};
try {
const privKey = new Buffer.from(WALLET_PRIVATE_KEY, 'hex');
const tx = new Tx.Transaction(rawTransaction);
tx.sign(privKey);
const serializedTx = tx.serialize();
console.log(`Attempting to send signed tx: ${serializedTx.toString('hex')}`);
const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
console.log(`Receipt info: ${JSON.stringify(receipt, null, '\t')}`);
}
catch (e) {
console.error('Failed to send transaction');
console.log(e.message);
}
};
my wallet private key is in this format (example):
7effd90c52ebcf6ff916a26e3053300ac10d4fecbcd0e46ae2ae861b120d8587
P.S. I use ethereumjs-tx
to make traction.
web3.utils.toWei("15", "gwei")
or you if you want to use a number instead of a string you can combine with toBN,web3.utils.toWei(web3.utils.toBN(15), "gwei")
.'gasPrice': '0x37E11D600', 'gasLimit': '0x2DC6C0',