When using with `@nomiclabs/hardhat-vyper`, resulting factories from vyper sources do not have correct ContractInterface type
Can be replicated with below repo.
https://github.com/penandlim/TestVyperPlugins
After successfully generating types, there are typescript errors in build/typechain/factories/HelloVyper.vy/HelloVyper__factory.ts.
Due to this type error, running test task results in errors.
npm ci
npx hardhat compile --no-typechain && npx hardhat typechain
npx hardhat test
Looks like gas properties inside the abis are set to number but ContractInterface expects it to be string
I've found this issue from last year on hardhat side but dont seem like much was done at the time.
https://github.com/NomicFoundation/hardhat/issues/1696
Stumbled upon this same issue, and for now manually updated the typechain *__factory.ts files such that:
const _abiNoGas = _abi.map( (element) => {
const {["gas"]: _, ...withoutGas } = element;
return withoutGas;
});
And set to use _abiNoGas instead of _abi.
It fixes two issues:
- typescript complaints that the gas field isn't a string
- Even if you stringify the gas field, the auto-generated gas estimation was actually incorrect - so contract function calls reverted (via hardhat/ethers) unless a large
{gasLimit}was manually provided.
@krzkaczor thoughts on a proposed solution? https://github.com/dethcrypto/TypeChain/pull/711
This fixes for me locally. @penandlim would you be able to test? Can git clone this branch: https://github.com/frontier159/TypeChain/tree/feature/exclude_gas_from_abi
And then in your project add it locally to yarn/npm/whatever:
npm install --save-dev file:/path/to/TypeChain/packages/target-ethers-v5
And your testVyper.ts needs a small tweak
beforeEach(async () => {
// const factory: HelloVyper__factory = new HelloVyper__factory()
const factory: HelloVyper__factory = await ethers.getContractFactory("HelloVyper")
testContract = (await factory.deploy()) as HelloVyper
})
But then works ok:
npx hardhat test
No need to generate any newer typings.
HelloSolidity
setGreeting
✔ Sets and prints Greeting
HelloVyper
setGreeting
✔ Sets and prints Greeting
2 passing (436ms)
This can be closed now: https://github.com/NomicFoundation/hardhat/pull/2879