I am trying to Deploy a beginners contract onto the rinkeby test network through Infura node. It is throwing the following error.
(node:35183) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The contract code couldn't be stored, please check your gas limit.
(node:35183) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Contract
pragma solidity ^0.4.17;
contract Inbox {
string public message;
function Inbox(
string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
} }
I used some console logs to determine where the error is being thrown, I have marked it below with a //COMMENT.
Deploy script
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'word frog gentle happy chicken book sneeze provide stick handle four fan',
'https://rinkeby.infura.io/myStringOfRandomLetters'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to Deploy from account', accounts[0]);
//ERROR OCCURS HERE
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({ gas: '1000000', from: accounts[0] });
console.log('Contract deployed to', result.options.address);
};
deploy();
Things I have tried to fix it:
Increasing the gas limit to 2,000,000, 4,000,000 and decreasing to around 500,000 and 21,000. I hit a "too small amount of gas" error, so I know gas amount is not the issue.
It may have been the npm module "truffle-hdwallet-provider" not installing properly, so I uninstalled, then sudo installed, then found the error fix on the internet (add --unsafe-perm to the commmand). like below
$ sudo npm install truffle-hdwallet-provider --unsafe-perm
still same error. I noticed another identical question Here however (as of now)it is also unanswered.
Deploy
script you're using - what is that? Is that another file? Cause all the tutorials I've seen say you're supposed to be doing all this using thetruffle.js
file. And then doing a Migrate inTerminal
to get all this deployed. So what are you doing?const result = await new web3.eth.Contract(JSON.parse(interface)) .deploy({ data: bytecode, arguments: ['Hi there!'] }) .send({ gas: '1000000', from: accounts[0] });
It usesHDWalletProvider
to connect to an infura node, which web3 uses to deploy through.