I don't know where i'm doing mistake. I have deployed my contract through remix and truffle and it was deployed without any mistake but now i'm deploying it from web3 [email protected] version and EVM is reverting my transaction.
Here's my code.
let privateKey = req.body.from_private_key;
let fromAddress = req.body.from_address;
let _startTime = req.body.startTime;
let _endTime = req.body.endTime;
let _goal = req.body.goal;
let _wallet = req.body.wallet;
_goal = web3.utils.toWei(_goal, 'ether');
web3.eth.defaultAccount = fromAddress;
let count = await web3.eth.getTransactionCount(web3.eth.defaultAccount);
let gasPrice = await web3.eth.getGasPrice();
let gasLimit = 3000000;
const result = await new web3.eth.Contract(JSON.parse(interface));
const deployData = result.deploy({
data: bytecode,
arguments: [_startTime, _endTime, _goal.toString(), _wallet]
}).encodeABI();
let tx = {
from: fromAddress,
nonce: web3.utils.toHex(count),
gasPrice: web3.utils.toHex(gasPrice),
gasLimit: web3.utils.toHex(gasLimit),
data: deployData,
chainId: 0x04
};
web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
});
Compiling from here:
const path = require('path')
const fs = require('fs');
const solc = require('solc')
const inboxPath = path.resolve(__dirname,'contracts','MyContract.sol')
const source = fs.readFileSync(inboxPath,'utf8');/
console.log(solc.compile(source.toString(),1));
module.exports =
solc.compile(source.toString(),1).contracts[':MyContract']
And Response is :
(node:22390) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Transaction has been reverted by the EVM: { "blockHash": "0xb6cbb03fcf1ea74b6dfa09d8fef7ed28fb3ec176a5b174de2d40ebabf1825965", "blockNumber": 4375769, "contractAddress": "0x33301cc2B245528D5F5720594148F16b05De1910", "cumulativeGasUsed": 3000000, "from": "0x57a9ce9d1e4834d43507ba77cb9d30f7dd0da307", "gasUsed": 3000000, "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": false, "to": null, "transactionHash": "0xa99d769d4965738eba5ebc33ccaf52c5b171bd66f758072bec55b7260932161c", "transactionIndex": 0 } (node:22390) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.