I'm learning how Ethereum Smart Contract are developed and deployed using solidity, web3 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 fail.
Ive sucessfully created web3
object using truffle-hdwallet-provider
and I sucessfullly get the account list but the deployment to the testnet always get failed.
You can check here that my deployment gets failed.
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;
}
}
EDIT: I tried using Remix and it deployed successfully but when trying with truffle-hdwallet-provider it gives 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.