0

I have this contract that when I try to deploy it with Fuji it sends me the gasLimit error and when I do it from Remix it returns the error description Gas estimation errored with the following message (see below). The transaction execution will likely fail. I leave my contract so you can understand it better. Thanks in advance

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

contract MultiSig {
    address[] public owners;
    uint public transactionCount;
    uint public required;

    event Confirmation(address indexed sender, uint indexed transactionId);
    event Submission(uint indexed transactionId);
    event Execution(uint indexed transactionId);
    event Deposit(address indexed sender, uint value);

    struct Transaction {
        address payable destination;
        uint value;
        bool executed;
        bytes data;
    }`enter code here`

    mapping(uint => Transaction) public transactions;
    mapping(uint => mapping(address => bool)) public confirmations;

    receive() payable external {
        emit Deposit(msg.sender, msg.value);
    }

    function getOwners() view public returns(address[] memory) {
        return owners;
    }

    function getTransactionIds(bool pending, bool executed) view public returns(uint[] memory) {
        uint count = getTransactionCount(pending, executed);
        uint[] memory txIds = new uint[](count);
        uint runningCount = 0;
        for(uint i = 0; i < transactionCount; i++) {
            if(pending && !transactions[i].executed ||
                executed && transactions[i].executed) {
                txIds[runningCount] = i;
                runningCount++;
            }
        }
        return txIds;
    }

    function getTransactionCount(bool pending, bool executed) view public returns(uint) {
        uint count = 0;
        for(uint i = 0; i < transactionCount; i++) {
            if(pending && !transactions[i].executed ||
                executed && transactions[i].executed) {
                count++;
            }
        }
        return count;
    }

    function executeTransaction(uint transactionId) public {
        require(isConfirmed(transactionId));
        emit Execution(transactionId);
        Transaction storage _tx = transactions[transactionId];
        (bool success, ) = _tx.destination.call{ value: _tx.value }(_tx.data);
        require(success, "Failed to execute transaction");
        _tx.executed = true;
    }

    function isConfirmed(uint transactionId) public view returns(bool) {
        return getConfirmationsCount(transactionId) >= required;
    }

    function getConfirmationsCount(uint transactionId) public view returns(uint) {
        uint count;
        for(uint i = 0; i < owners.length; i++) {
            if(confirmations[transactionId][owners[i]]) {
                count++;
            }
        }
        return count;
    }

    function getConfirmations(uint transactionId) public view returns(address[] memory) {
        address[] memory confirmed = new address[](getConfirmationsCount(transactionId));
        uint runningConfirmed;
        for(uint i = 0; i < owners.length; i++) {
            if(confirmations[transactionId][owners[i]]) {
                confirmed[runningConfirmed] = owners[i];
                runningConfirmed++;
            }
        }
        return confirmed;
    }

    function isOwner(address addr) private view returns(bool) {
        for(uint i = 0; i < owners.length; i++) {
            if(owners[i] == addr) {
                return true;
            }
        }
        return false;
    }

    function submitTransaction(address payable dest, uint value, bytes memory data) public {
        uint id = addTransaction(dest, value, data);
        confirmTransaction(id);
        emit Submission(id);
    }

    function confirmTransaction(uint transactionId) public {
        require(isOwner(msg.sender));
        emit Confirmation(msg.sender, transactionId);
        confirmations[transactionId][msg.sender] = true;
        if(isConfirmed(transactionId)) {
            executeTransaction(transactionId);
        }
    }

    function addTransaction(address payable destination, uint value, bytes memory data) public returns(uint) {
        transactions[transactionCount] = Transaction(destination, value, false, data);
        transactionCount += 1;
        return transactionCount - 1;
        
    }

    constructor(address[] memory _owners, uint _confirmations) {
        require(_owners.length > 0);
        require(_confirmations > 0);
        require(_confirmations <= _owners.length);
        owners = _owners;
        required = _confirmations;
    }
}

When it comes to deploy it only deploys locally with Hardhat correctly. But it increases my fees a lot. And the test passes without problems.

deploy.js

const hre = require("hardhat");

async function main() {
  const accounts = await ethers.provider.listAccounts();
  const MultiSig = await ethers.getContractFactory("MultiSig");
  const multiSig = await MultiSig.deploy(accounts, 2);

  await multiSig.deployed();

  console.log("MultiSig deployed to:", multiSig.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

hardhat.config.js

require('@nomiclabs/hardhat-ethers');
require('@openzeppelin/hardhat-upgrades');
require("@nomiclabs/hardhat-waffle");
require("dotenv").config()


const FUJI_RPC_URL =
  process.env.FUJI_RPC_URL

const PRIVATE_KEY = 
  process.env.PRIVATE_KEY

const SUBNET_RPC_URL =
  process.env.SUBNET_RPC_URL

const PRIVATE_KEY_ADMIN = 
  process.env.PRIVATE_KEY_ADMIN

module.exports = {
  solidity: "0.8.15",
  paths: {
    artifacts: "./src/backend/artifacts",
    sources: "./src/backend/contracts",
    cache: "./src/backend/cache",
    tests: "./src/backend/test"
    },
  defaultNetwork: 'hardhat',
  networks: {
    hardhat: {
    chainId: 1337 // We set 1337 to make interacting with MetaMask simpler
    },
    fuji: {
    url: FUJI_RPC_URL,
    accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
    },
    subnet: {
    url: SUBNET_RPC_URL,
    accounts: PRIVATE_KEY_ADMIN !== undefined ? [PRIVATE_KEY_ADMIN] : [],
    },
  },
};
  • I deployed the same code on fuji and it is working fine. https://testnet.snowtrace.io/address/0xEc99EF7041eEB59f9623f08B55f2e569BB4990Ef – Muhammad Hassan Oct 04 '22 at 18:24
  • Wow, it really did deploy. What could I be running wrong? Show me your deploy file. Maybe I have something wrong there. – luislucena Oct 05 '22 at 07:33
  • I deployed it via remix, I forgot to mention yesterday that you gotta have a constructor right in the beginning, you can show me your deployment file, and hardhat config I can have a look. – Muhammad Hassan Oct 05 '22 at 07:43
  • Oh, I understand! Of course you do. I'll show you my files. I have edited my initial question where I have put more clearly the `deploy` and the `hardhat.config.js`. I have put them in to make it look better. Here the code was not very readable. – luislucena Oct 05 '22 at 08:14

1 Answers1

0

try changing the deployment script to

const hre = require("hardhat");

async function main() {
  const accounts = await ethers.getSigners();;
  const MultiSig = await ethers.getContractFactory("MultiSig");
  const multiSig = await MultiSig.deploy(accounts[0].address, 2);

  await multiSig.deployed();

  console.log("MultiSig deployed to:", multiSig.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });
Muhammad Hassan
  • 424
  • 3
  • 5