0

This is my solidity function:

function bid(uint256 bidAmount) public payable {
        require(vault.tokenExists(address(nftAddress), nftId, owner) == true, "There are no units of this token available for sale!");
        require(msg.value == bidAmount, "Bid amount must be equal to sent value");
        require(block.timestamp < endTime, "Auction has already ended");
        require(bidAmount > winningBid, "Bid amount must be greater than the winning bid");

        //Refund the previous winner's bid
        if (winner != address(0)) {
            winner.transfer(winningBid);
            emit BidRefunded(winner, winningBid);
        }

        // Add the new bid to the mapping and update the winning bid
        bids[msg.sender].push(Bid({bidder: payable(msg.sender), bidAmount: bidAmount}));
        winningBid = bidAmount;
        winner = payable(msg.sender);
        emit NewBid(msg.sender, bidAmount);
    }

I am trying to execute it using hardhat js:

  const Auction = await AuctionContract.attach('0xA6558F9fEDD69F55B056b5233a1cFcad9d45d242');
  const user_signer = new ethers.Wallet(account_one_privateKey, provider);
  const tokenPrice1 = ethers.utils.parseEther('0.0000000000000002');
  const sendValue = {
  value: tokenPrice1,
  };
  const Bid = await Auction.connect(user_signer).bid(200000,sendValue);
  console.log(Bid);
  console.log(Bid.hash);

its throwing me this error:

    reason: 'processing response error',
        code: 'SERVER_ERROR',
        body: '{"jsonrpc":"2.0","id":49,"error":
{"code":-32000,"message":"insufficient funds for transfer"}}\n',
1
  • the account_one_privateKey doesn't have money, that's why it gives you this error
    – Nulik
    Mar 2 at 21:29

1 Answer 1

0

Which provider are you using? As I guess you're wanna run the script on a specified network, you should:

  1. Define network inside hardhat.config, like:
networks: {
    polygonMumbai: {
      url: "https://matic-mumbai.chainstacklabs.com",
      chainId: 80001,
      accounts: ["your_private_key"]
    }
}
  1. Run your script with the command:
npx hardhat run path_to_script --network polygonMumbai

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.