Reputation: 472
I'm learning how Ethereum smartcontracts are developed and deployed using Solidity, Web3.js, and JavaScript.
I've successfully deployed a contract on Ganache. Now when I'm trying to deployed it on Rinkby Test Net using `truffle-hdwallet-provider. It just fails.
Ive successfully created a web3 object using truffle-hdwallet-provider and I successfully get the account list but the deployment to the testnet always fails.
You can check here that my deployment fails: https://rinkeby.etherscan.io/address/0x2f20b8F61813Df4e114D06123Db555325173F178
Here is my deploy script
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require ('web3');
const {interface, bytecode} = require('./compile');
const provider = new HDWalletProvider(
'memonics', // this is correct
'https://rinkeby.infura.io/mylink' // this is correct
);
const web3 = new Web3(provider);
const deploy = async() =>{
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account:', accounts[0]); //This excute fine
try {
const result = await new web3.eth.Contract(JSON.parse(interface)).deploy({ data: bytecode, arguments: ['Hi There!']}).send({ from: accounts[0], gas: '1000000'});
console.log('Contract deployed to ', result.options.address);
}
catch(err) {
console.log('ERROR'); // Here I get error
}
};
deploy();
and here is my Contract
pragma solidity ^0.4.17;
contract Inbox{
string public message;
constructor (string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
I tried using Remix and it deployed successfully but when trying with truffle-hdwallet-provider it gives this error:
The contract code couldn't be stored, please check your gas limit.
I tied with different gas values (up-to max possible) but still no result.
Upvotes: 4
Views: 2340
Reputation: 1
when deploying to sepolia network, i did this and it worked out fine :
const result = await new web3.eth.Contract(interface)
.deploy({data: '0x' + bytecode, arguments: ['Hello there']})
.send({from: accounts[0], gas: '1000000'})
just affix '0x' to the bytecode
Upvotes: 0
Reputation: 472
I figured out the bytecode not including 0x
caused this problem.
By concatenating 0x
with the bytecode, I was able to get it to work.
Upvotes: 0
Reputation: 71
Use this '0x0' +
inside deploy
just before bytecode.
.deploy({ data:'0x0' + bytecode })
.send({ gas: "1000000", gasPrice: "5000000000", from: accounts[0] });
Upvotes: 4
Reputation: 101
I had this problem, and solved it by pasting the flattened code into Remix that then gave a better error description: I had an interface in the contract that I had not implemented correctly (wrong function signature). Check your interface implementations. Trying to deploy an "abstract contract" gives this error.
Upvotes: 0