0

I created a script that fetches the WETH interface and send some test ETH

getWeth.js

const { getNamedAccounts, ethers } = require("hardhat")

const AMOUNT = ethers.parseEther("0.1")

async function getWeth() {
    const { deployer } = await getNamedAccounts()
    const iWeth = await ethers.getContractAt(
        "IWeth",
        "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        deployer,
    )
    const txResponse = await iWeth.deposit({
        value: AMOUNT,
    })
    await txResponse.wait(1)
    const wethBalance = await iWeth.balanceOf(deployer)
    console.log(`Got ${wethBalance.toString()} WETH`)
}

module.exports = { getWeth, AMOUNT }

aaveBorrow.js

const { getWeth } = require("../scripts/getWeth")

async function main() {
    await getWeth()
}

main()
    .then(() => process.exit(0))
    .catch((err) => console.log(err))

When I run the scripts using yarn hardhat run scripts/aaveBorrow.js

I am returned with and error

TypeError: unsupported addressable value (argument="target", value=null, code=INVALID_ARGUMENT, version=6.11.1)
    at makeError (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/utils/errors.ts:687:21)
    at assert (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/utils/errors.ts:715:25)
    at assertArgument (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/utils/errors.ts:727:5)
    at resolveAddress (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/address/checks.ts:122:19)
    at /home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/contract/contract.ts:172:60
    at ParamType.#walkAsync (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/abi/fragments.ts:779:24)
    at ParamType.walkAsync (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/abi/fragments.ts:797:24)
    at /home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/contract/contract.ts:170:22
    at Array.map (<anonymous>)
    at resolveArgs (/home/raaghavmanivel/hardhat-defi/node_modules/ethers/src.ts/contract/contract.ts:169:37) {
  code: 'INVALID_ARGUMENT',
  argument: 'target',
  value: undefined,
  shortMessage: 'unsupported addressable value'

1 Answer 1

0

You need to pass the signer instead of deployer in the getContractAt() function, because the transaction corresponding to the deposit() function needs to be signed.

The signer can be created from the deployer like this:

const signer = await ethers.getSigner(deployer);

Hence, the revised code for getWeth.js file would be:

const { getNamedAccounts, ethers } = require("hardhat")

const AMOUNT = ethers.parseEther("0.1")

async function getWeth() {
    const { deployer } = await getNamedAccounts()

    const signer = await ethers.getSigner(deployer);

    const iWeth = await ethers.getContractAt(
        "IWeth",
        "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        signer
    );
    const txResponse = await iWeth.deposit({
        value: AMOUNT,
    })
    await txResponse.wait(1)
    const wethBalance = await iWeth.balanceOf(deployer)
    console.log(`Got ${wethBalance.toString()} WETH`)
}

module.exports = { getWeth, AMOUNT }
2
  • Thank you,That worked.But I have one more question,when I tried commenting out line by line on the earlier program, the getContrractAt and transfer function passed and I got an error only at the balanceOf function. Also,what exactly is the difference between deployer and signer? Mar 20 at 3:49
  • @RaaghavManivel, if you hover over getContractAt function, then you can see the params that it's expecting as well as its return type ( i.e., (property) HardhatEthersHelpers.getContractAt: (nameOrAbi: string | any[], address: string | Addressable, signer?: Signer | undefined) => Promise<Contract> ). So, it can't work with passing the deployer (i.e., an address/wallet address), it needs the signer (i.e., an object that can sign the transactions, and it's being created by the combination of RPC of the network and the private key corresponding to the deployer address). Mar 20 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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