0

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 solc@0.4.24 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.

bumped to the homepage by Community 19 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

From the stack trace in your transaction https://rinkeby.etherscan.io/vmtrace?txhash=0xa99d769d4965738eba5ebc33ccaf52c5b171bd66f758072bec55b7260932161c

Step    PC      Operation     Gas            GasCost    Depth
[1]     0       DUP1          2721080        0          1

Its seems the beginning of your bytecode is wrong.

0x806040526000600455600580...
  • Here is my deployed contract on rinkeby which is deployed through remix. i don't how starting of my bytecode is going wrong here in web3. rinkeby.etherscan.io/address/… – Hamza Yasin May 14 at 10:08
  • @HamzaYasin How do you create bytecode? The contract at the address you point starts with 0x6080604052600060045560006005. – Ismael May 14 at 17:15
  • I'm creating it through solc@0.4.24 – Hamza Yasin May 14 at 17:17
  • @HamzaYasin How do you create contract bytecode? From commandline (which command), from a script (which scripts)? If you execute console.log(bytecode) before deploy what does it looks like? Did you try first deploying a "hello world" contract to ensure your script is working? Either your bytecode is erroneouly generated or in another part of your script it cuts the beginning. – Ismael May 14 at 18:50
  • Please see above i have updated my question with my compiling scrypt. Another thing i have my contract is in flat file of solidity, it was consisting of 6, 7 contract files and i made it a single flat file to compile and deploy from here. – Hamza Yasin May 15 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.