Guide to deploying a factory contract using solidity @0.5.0 with Node.js

Repository: https://github.com/aljmiller87/ethereum-dispute-resolution

In my solidity file @0.5.0, I have a Factory Contract and a child contract. Although I am able to compile it with some trial and error noted in the commented-out lines in ethereum/compile.js.

However, when I run node ethereum/deploy.js, I encounter an error:

Attempting to deploy from account 0xff831110eeA8322639bee543AD1477AD9f472E22 
UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit.
...
...
...
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:24059) [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.

I have verified that this contract code works in remix. Additionally, I've attempted using truffle-hdwallet-provider on versions 0.0.3 and 0.0.5, updating the arguments accordingly for both .deploy() and .send().

This exact setup has been successful in another project @ solidity 0.4.17 where deploying worked fine. Here's the repository for the previous project: https://github.com/aljmiller87/ethereum-kickstart

Repository Link:https://github.com/aljmiller87/ethereum-dispute-resolution

ethereum/deploy.js

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const compiledContract = require('./build/ThreeJudge.json');

const compiledFactory = compiledContract.ContractFactory
const compiledFactoryABI = compiledFactory.abi;
const compiledFactoryBytecode = compiledFactory.evm.bytecode.object;


const provider = new HDWalletProvider(
    `${process.env.SEED_KEY}`,
    'https://rinkeby.infura.io/v3/ad66eb1337e043b2b50abe1323fff5f0'
);

const web3 = new Web3(provider);

const deploy = async () => {
    // Get account to deploy from
    const accounts = await web3.eth.getAccounts();
    console.log('Attempting to deploy from account', accounts[0]);

    // deploy code
    const result = await new web3.eth.Contract(compiledFactoryABI)
    .deploy({ data: '0x' + compiledFactoryBytecode })
    .send({ gas: '1000000', from: accounts[0] });


    console.log('result address', result.options.address)
};

deploy();


package.json:

{
  "name": "kickstart",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha test/ThreeJudge.test.js --timeout 10000",
    "test-local": "mocha test/ThreeJudge-local.test.js --timeout 10000",
    "dev": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "dotenv": "^8.0.0",
    "fs-extra": "^8.1.0",
    "ganache-cli": "^6.5.0",
    "mocha": "^6.1.4",
    "next": "^4.1.4",
    "next-routes": "^1.4.2",
    "path": "^0.12.7",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "semantic-ui-css": "^2.4.1",
    "semantic-ui-react": "^0.87.3",
    "solc": "0.5.2",
    "truffle-hdwallet-provider": "0.0.5",
    "web3": "^1.0.0-beta.37"
  }
}

When running node ethereum/deploy.js, I encounter the following error:

Attempting to deploy from account 0xff831110eeA8322639bee543AD1477AD9f472E22
(node:24059) UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit.
    at Object.callback (/Users/alexmiller/Projects/solidity/threejudges/node_modules/web3-core-method/src/index.js:333:46)
    ...
    ...
    ...
(node:24059) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:24059) [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.

Answer №1

If you're looking to save on gas fees, consider using a clone factory contract instead of the new keyword. Check out this reference link: clone-factory and also learn why it's more efficient in this article "Attack Of The Clones — How DDA Contracts Are So Cheap To Deploy"

Answer №2

Discovered that the issue lied within the solidity code. Instead of keeping an array of the Contract type, I mistakenly attempted to store the addresses of the contracts created.

Initial Code Snippet:

contract ContractFactory {
    ThreeJudge[] public deployedContracts;

    function createContract(address payable _buyer, address payable _seller) public {
        ThreeJudge newContract = new ThreeJudge(_buyer, _seller);
        deployedContracts.push(newContract);
    }

    function getDeployedContracts() public view returns (ThreeJudge[] memory) {
        return deployedContracts;
    }
}

contract ThreeJudge {
...

Corrected Version:

contract ContractFactory {
    address[] public deployedContracts;

    function createContract(address payable _buyer, address payable _seller) public {
        ThreeJudge newContract = new ThreeJudge(_buyer, _seller);
        deployedContracts.push(address(newContract));
    }

    function getCampaignsByAddress() public view returns (address[] memory) {
        return deployedContracts;
    }
}

contract ThreeJudge {
...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Employing parseFloat() and parseInt() functions together with regular expressions in JavaScript for converting a Comma Separated Values (CSV

I've been working on converting a CSV file to a local 2D array and I'm curious if there's a more efficient method of changing strings to floats/int rather than relying on regex paired with parseFloat() / parseInt. Any bright ideas or sugges ...

"Troubleshooting Dojo Drag and Drop Problem: Transformation of Data into JSON Format within the Destination Container

I am working with two DND containers, SourceContainer and TargetContainer. The SourceContainer contains some JSON data as shown below: Apple Orange Banana This JSON is being used: var json = {"fruits": [ {"fruitId": 1, "fruitName": "Apple", ...

How to disable React Native yellow warnings in console using npm

Is there a way to get rid of those pesky yellow warnings flooding my npm console? It's becoming impossible to spot my own console.log messages amidst all the warning clutter. https://i.stack.imgur.com/JAMEa.jpg I've already attempted the follow ...

Modifying subtotal values using PHP and JavaScript

I've been working on this code snippet to calculate my subtotal and determine the total payment. Can someone provide some assistance? $viewx = mysql_query("select distinct toorderid from ordercontainer where toordercategory='$ordercategory' ...

Converting an ajax request from jQuery to pure JavaScript

Is there a way to convert this jQuery Ajax to plain Javascript? $("#newsLetter-form").on('submit',function(event){ event.preventDefault(); email = $('#emailId').val(); console.log(email); $.aj ...

I keep receiving a 400 (Bad Request) error when trying to delete with my REST API

I've successfully created an API and have managed to make POST and GET requests work flawlessly. However, I'm facing some trouble with the DELETE request. Every time I try to execute it, I encounter a 'DELETE http://localhost:3000/api 400 (B ...

Leverage lodash operators within nested object properties

My data consists of an array of objects { "agent_name": "AgentName", "analytics": [ { "date": "Tue, 1 Aug 2021 00:00:00 GMT", "intents_count":[ { "coun ...

Show a toast message and reset the form upon submission

Here I have created a contact form using HTML, CSS, and JavaScript. However, I'm facing an issue where the form redirects me to a page displaying the submitted details after clicking the submit button. I want to display a toast message instead and res ...

Top jQuery Extension for Latest Updates

I need to display 10 images with corresponding numbers (1,2,3,4,5...). Specifically, I am looking for a jQuery plugin that allows for an image slideshow with numbered navigation. Any recommendations? ...

Building a table with the appendChild() method

I'm a beginner in the world of programming and I've been given a task to create a table of objects. I managed to do it using a certain method, but now I'd like to try creating it using the appendChild method. function addObject() { var ...

Tips for composing a hyperlink within a property

I'm a newbie to Vue.js and facing a challenge with assigning a property to a link. I'm unsure of how to write the "counter" variable from "data" in order for it to properly function as intended. export default { name: 'app', data ( ...

Unable to resolve the issue of Duplicate keys detected with value '0'. This could potentially lead to errors during updates

Encountered a warning in Vue js stating 'Duplicate keys detected: '0'. This warning could potentially lead to an update error. To resolve this issue, I utilized the getter and setter in the computed variable and dispatched the value to Vuex ...

Tips on achieving a responsive image layout design

Trying to implement this design using Tailwind CSS and Next.js for coding this component: I'm facing challenges in achieving the desired grid layout with images, as they are not displaying properly. Below is my current approach: import Image from &a ...

How can JavaScript be used to identify duplicate elements within an array?

In a recent interview, I was tasked with finding repetitive elements in an array. While I was able to do so using a for loop, the interviewer requested a more efficient method without using a for loop. I am relatively new to exploring Java script and would ...

Is it possible to nest components within one another in Angular?

It seems similar to this: <app-component1> <app-component2></app-component2> </app-component1> I couldn't locate any information about this in the Angular documentation. Whenever I try to use a component within another com ...

Skipping validation while navigating back on SmartWizardIf you need to bypass validation during backward

Looking for assistance with Jquery smartwizard? Check out the link. I want to disable validation when a user clicks on the "Previous" button in any step, except for the first step where the Previous button is disabled by default. Below is my JavaScript co ...

Ever since updating my jQuery version to 3.2.1, my ajax code seems to have stopped functioning properly

My program's ajax functionality was running smoothly with jquery version 1.7, but when I updated to version 3.3.1, the ajax part stopped working. I made sure to attach the ajax portion of my code after updating the jQuery version. In the PHP file, I s ...

Sharing Data Across Multiple Windows in Angular 2 Using a Singleton List

My multiplayer game involves adding new players to a single game room lobby, which is essentially a list of current players. How can I update this list for all connected players when new ones join? I implemented a service and included it in the providers ...

The AJAX response enters a continuous loop if it contains the window.print function

I'm looking to print the screen upon receiving an ajax response. Here's my code snippet: function initiatePrint() { var request = new XMLHttpRequest(); request .open("GET", "printPage.html", true); var counter = 0; ...

console fails to return a function even when it is defined

After clicking the "stopCrash" button, I want the function backAgain to be executed 2 seconds later. However, I am encountering an error in the console: Uncaught TypeError: this.backAgain is not a function. Do you have any suggestions on how to fix this i ...