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.
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.