truffle-hdwallet-provider icon indicating copy to clipboard operation
truffle-hdwallet-provider copied to clipboard

Cannot create contract

Open entrptaher opened this issue 6 years ago • 6 comments

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
  • https://rinkeby.etherscan.io/tx/0x0bdec7f861443e172095a29c0bb040a28aea07877b51a6716cfefc67ce34f8fa

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.
  • https://rinkeby.etherscan.io/tx/0x3501f5735ad298b705e084b3524cd3c0a7c4909995ce4005b2160f26ba3cd87e

entrptaher avatar May 10 '18 22:05 entrptaher

I also experienced the same issue.

DavidPetit avatar May 24 '18 07:05 DavidPetit

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] });

johanforslund avatar Jul 01 '18 10:07 johanforslund

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

plat123456789 avatar Aug 12 '18 14:08 plat123456789

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.

joepagan avatar Nov 21 '18 14:11 joepagan

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

rawadrifai avatar Nov 22 '18 01:11 rawadrifai

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)

manasranjanmhnt avatar Feb 03 '20 05:02 manasranjanmhnt