PatrickAlphaC / ethers-simple-storage-fcc

90 stars 128 forks source link

no matching function error on contractFactory.deploy() #86

Closed ediber closed 1 year ago

ediber commented 1 year ago

i got the following error on the "await" part of my code TypeError: no matching function (argument="key", value="address", code=INVALID_ARGUMENT, version=6.6.0) a recompiled my SimpleStorage so I believe the bin and abi files match the solidity code. i also see in Ganache that TX COUNT of the relevant adress is doing ++, but the balance is still 100 eth(no change) thanks a lot guys

my deploy code

const ethers = require("ethers");
const fs = require("fs-extra");

async function main() {
  // gives me the blockchain, ganahe blockchain in our case
  const provider = new ethers.JsonRpcProvider("HTTP://172.24.0.1:7545"); ///////////

  // gives me the wallet, private key is one of the adress from ganache blockchain
  const wallet = new ethers.Wallet(
    "0x1cad729703311077190aea80c08181aa17cc47f823ae85aef2f4d4338c13ea48",
    provider
  );

  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf8"
  );

  // connects the contract to a wallet
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  // console.log("contractFactory", contractFactory);
  console.log("Deploying contract...");
  const contract = await contractFactory.deploy();
  console.log("Contract deployed to address:", contract.address);
}

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

my simple storage code

pragma solidity ^0.8.7;

// pragma solidity ^0.8.0;
// pragma solidity >=0.8.0 <0.9.0;

contract SimpleStorage {
    uint256 favoriteNumber;

    struct People {
        uint256 favoriteNumber;
        string name;
    }
    // uint256[] public anArray;
    People[] public people;

    mapping(string => uint256) public nameToFavoriteNumber;

    function store(uint256 _favoriteNumber) public {
        favoriteNumber = _favoriteNumber;
    }

    function retrieve() public view returns (uint256) {
        return favoriteNumber;
    }

    function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }
}
PatrickAlphaC commented 1 year ago

This means your wallet is being set up incorrectly. Are you using a key or address from ganache?

ediber commented 1 year ago

i use a private key of one of the addresses in Ganache is it the correct way to go ? i added screenshot example of the string i have in my code from ganache. now the address is different, but i added it to ask if i use the correct way to get private key

Capture

PatrickAlphaC commented 1 year ago

Hmm.... this looks correct. Perhaps you're having an issue with windows? You could skip this section and go right to hardhat.

Anything here help?

https://github.com/smartcontractkit/full-blockchain-solidity-course-js/blob/main/chronological-updates.md#windows-wsl--ganache

ediber commented 1 year ago

yesteday i saw you have a new course so im following it and everything works there for now with foundy thanks a lot your courses are the best i have ever seen thank you for everything :)

PatrickAlphaC commented 1 year ago

Great! I'll close this for now.