Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
contract call run out of gas and made the transaction revert HardHat

I am trying to test solidity ^0.8.0 smart contract. And I am getting error error message

Here is part of code Solidity:

    receive () external payable {
    require (msg.value > 0, "Empty transact");
    require (saleStart + 48 days > block.timestamp, "ICO is over"); 
    require (msg.value / 1000000000000000000 % 1 == 0, "Fractional numbers are not allowed");

    if (saleStart + 3 days > block.timestamp) {
        addToBalance(msg.sender, msg.value, 1);
        }
    else if (saleStart + 34 days > block.timestamp) {
        addToBalance(msg.sender, msg.value, 2);
        }

    else if (saleStart + 48 days > block.timestamp ) {
        addToBalance(msg.sender, msg.value, 3);
        }
}

and JS HardHat

const { expect } = require("chai");
const { ethers, waffle } = require("hardhat");

beforeEach(async function(){
    [owner, acc1, acc2, acc3 ] = await ethers.getSigners()
    const ICO = await ethers.getContractFactory("ICO", owner)
    ico = await ICO.deploy()
    await ico.deployed()
})
    it("contract receive ether", async function(){
    const tx = await ico.connect(acc1).pay(ico.address, { value : 100000, gasLimit: 30000000 })
    await tx.wait()
    const owner_balance = await provider.getBalance(owner.address)
    const acc1_balance = await provider.getBalance(acc1.address);
    console.log(owner_balance)
    console.log(acc1_balance)
})

Also I tried to use receive() function without any code inside and it works. It seems problem I change some information in blockchane, and it's require gas. But Also I tried receive() function with code inside in Rinkeby testnet and it works. How to solve problem with gas?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!