What do I need to change in order to have a successful transaction on the EVM? Where have I gone wrong in the below code.
What I have done
I'm trying to send tokens from my wallet address using Web3 to another wallet address. Below is how I attempted to do this but my transactions are never successful.
Initing my token web3 and ABI code
//TestAccount01
const TA1 = {
address: '0x57ece112876fb585c6a2b37114c91be752b7578c',
privateKey:
'privatekey',
};
const Web3 = require('web3');
const web3 = new Web3(
'https://rinkeby.infura.io/v3/api_endpint_url_id'
);
let minABI = [
// transfer
{
constant: false,
inputs: [
{
name: '_to',
type: 'address',
},
{
name: '_value',
type: 'uint256',
},
],
name: 'transfer',
outputs: [
{
name: '',
type: 'bool',
},
],
type: 'function',
},
];
The function that sends token TXNs to address
async function sendToken() {
let contract = new web3.eth.Contract(
minABI,
//contract address
'0xD92E713d051C37EbB2561803a3b5FBAbc4962431'
);
let tx = await contract.methods.transfer(TA1.address, 1000);
let data = tx.encodeABI();
let gas = 61963;
let gasPrice = 1649999980;
console.log('creating transaction');
let transaction = await web3.eth.accounts.signTransaction(
{
data,
gas,
gasPrice,
},
'my private key'
);
console.log('sending transaction');
let recipt = await web3.eth
.sendSignedTransaction(transaction.rawTransaction)
.catch(err => {
console.log('error in sending tx');
console.error(err);
});
console.log(recipt);
}
await sendToken();
This gives me the error Error: Transaction has been reverted by the EVM:
And a transaction hash of 0x7f0ca267163219d2c8c783e9fdc8ec3a4c1d1c0c1c52d6a405c3763cac240d9c
witch you can see for your self at https://rinkeby.etherscan.io/tx/0x7f0ca267163219d2c8c783e9fdc8ec3a4c1d1c0c1c52d6a405c3763cac240d9c
I have tried changing many of the variables (especially the gas and Ga) in an attempt to get tokens to send from my address to TA1.address
but the transaction keeps getting reverted by EVM
Another thing. I have noticed that no matter how high I set my gas limit, Etherscan says it has used 100% of it. I have set a gas limit to very high numbers and still, usage is always 100%.