trufflesuite / truffle-hdwallet-provider

HD Wallet-enabled Web3 provider
MIT License
400 stars 167 forks source link

Cannot create contract #33

Open entrptaher opened 6 years ago

entrptaher commented 6 years ago

Creating a contract using version 0.0.3 works where 0.0.4 and 0.0.5 fails.

Sample code:

Packages:

"ganache-cli": "^6.1.0",
"solc": "^0.4.23",
"truffle-hdwallet-provider": "^0.0.3", // <-- anything other than 0.0.3 fails
"web3": "^1.0.0-beta.34"

contract file:

pragma solidity ^0.4.23;
contract Inbox {
    string public message;   
    constructor(string initalMessage) public payable {
        message = initalMessage;
    }   
    function setMessage(string newMessage) public {
        message = newMessage;
    }
}

Deploy file:

require('dotenv').config()

const HDWalletProvider = require("truffle-hdwallet-provider");
const Web3 = require("web3");
const { interface, bytecode } = require("./compile");
const provider = new HDWalletProvider(
  process.env.SECRET,
  process.env.SERVER
);

const web3 = new Web3(provider);
const deploy = async () => {
  const accounts = await web3.eth.getAccounts();
  console.log(`Deploying from account`, accounts[0]);
  const result = await new web3.eth.Contract(JSON.parse(interface))
    .deploy({
      data: bytecode,
      arguments: ["Hi there!"]
    })
    .send({
      gas: "1000000",
      from: accounts[0],
      // same even if I add a gasPrice param here
    });
  console.log(`Contract deployed to`, result.options.address);
};
deploy();

Sample success transactions:

LOG:

Attempting to deploy from account 0xc2996Ecd48c424dADdFB00A4a78cfe59e52eF30e
Contract deploy to 0x324B3A459E01Dc9EF728B57BC49e75488496eA84

Sample failed transactions:

LOG:

➜  inbox node deploy.js
Attempting to deploy from account 0xc2996Ecd48c424dADdFB00A4a78cfe59e52eF30e
(node:1907) UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit.
DavidPetit commented 6 years ago

I also experienced the same issue.

johanforslund commented 6 years ago

Did you solve this? EDIT: Adding '0x' to the data value worked for me.

const result = await new web3.eth.Contract(JSON.parse(compiledFactory.interface))
    .deploy({ data: '0x' + compiledFactory.bytecode })
    .send({ gas: '3000000', from: accounts[0] });
plat123456789 commented 6 years ago

i have the same problem, Adding '0x' to the data help

joepagan commented 5 years ago

Got this issue in 0.0.6 Reverting to 0.0.3 worked for me Prepending 0x to the bytecode worked for me in 0.0.6

Maybe the issue isn't with this package but the bytecode needs to be parsed better? No idea at which point that should be addressed.

rawadrifai commented 5 years ago

running into a very similar issue. stuck for over 48 hours if anyone could help, would be greatly appreciated: https://github.com/trufflesuite/truffle-hdwallet-provider/issues/78

manasranjanmhnt commented 4 years ago

Getting below error.

"before each" hook for "deploys a contract": Error: Invalid number of parameters for "undefined". Got 0 expected 1! at Object.InvalidNumberOfParams (node_modules\web3-core-helpers\src\errors.js:32:16) at Object._createTxObject (node_modules\web3-eth-contract\src\index.js:791:22) at Contract.deploy (node_modules\web3-eth-contract\src\index.js:596:33) at Context.beforeEach (test\Inbox.test.js:48:4) at process._tickCallback (internal/process/next_tick.js:68:7)