Hey guys I am running into an issue deploying a smart contract with Web3 to the Ropsten network. The code is running seemingly correctly, and there is a contract address being created, but if I check the transaction hash on Etherscan it shows that there has been an error in executing the contract. I don't think it's the contract itself as I've tested a couple contracts and they both have the same error.
const fs = require("fs");
const solc = require('solc');
let Web3 = require('web3');
const Tx = require('ethereumjs-tx').Transaction;
const testnet = 'https://ropsten.infura.io/v3/APIKEY';
const address = '0x0764eDcCD0278Ee60C421148B8baB812306D90D5';
const privateKeyValue = 'PRIVATEKEY';
const privateKey = new Buffer(privateKeyValue, 'hex');
const web3 = new Web3(new Web3.providers.HttpProvider(testnet));
const input = fs.readFileSync('contract3.sol');
const output = solc.compile(input.toString(), 1);
const abi = JSON.parse(output.contracts[':ERC20Interface'].interface);
const contract = new web3.eth.Contract(abi);
const weiAmount = web3.utils.toWei('1', 'ether');
let data = contract.methods.transfer(address, weiAmount).encodeABI();
async function main(){
const gasPrice = await web3.eth.getGasPrice();
const gasPriceHex = await web3.utils.toHex(gasPrice);
const gasLimitHex = await web3.utils.toHex(7957355);
const nonce = await web3.eth.getTransactionCount(address);
const nonceHex = await web3.utils.toHex(nonce);
const rawTx = {
// from: address,
nonce: nonceHex,
gasPrice: gasPriceHex,
gasLimit: gasLimitHex,
data: data,
value: web3.utils.toHex("97534000000000000"),
chainId: web3.utils.toHex(3),
};
const tx = new Tx(rawTx, {'chain':'ropsten'});
tx.sign(privateKey);
const serializedTx = tx.serialize();
console.log(serializedTx + 'serialized tx');
const promiseEvent = web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
return promiseEvent
.on('transactionHash', (txHash) => {
console.log('TRANSACTION HASH');
console.log(txHash);
console.log('TRANSACTION HASH');
}
)
.on('confirmation', (confirmNumber, receipt) => {
console.log('CONFIRM NUMBER, RECEIPT');
console.log(confirmNumber, receipt);
console.log('CONFIRM NUMBER, RECEIPT');
}
)
.on('error', (error => {
console.log('ERROR');
console.log(error);
console.log('ERROR');
})
);
}
main();
Here's a link to the transaction hash: https://ropsten.etherscan.io/tx/0x8f703e3f87486baa60725186e9469d65f8355af94c8f9f43baae2d4aa5cb39b0
Versions are as follows: Web3 = 1.2.1 ethereumjs-tx = 2.1.0 solc = 0.4.25
Does anything seem out of sorts here? This is my first project trying to deploy a smart contract so I'm uncertain of the error and the tinkering I've been doing has been fruitless so far. Thanks!