Hardhat Integration and CLI Documentation #1013
-
I discovered this repository and try to find out how I can replace TypeChain. I found the following package: https://www.npmjs.com/package/@evmts/ethers But it's not clear for me how to generate ts files from the contract. CLI page in documentation is under construction currently. Can someone show a quick example usage in hardhat. // import a contract with evmts
import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol'
import {providers} from 'ethers'
// create a provider or signer for the ethers contract
const provider = new providers.JsonRpcProvider('http://localhost:8545')
// create a typesafe contract
const contract = createEthersContract(myContract, {chainId: 1, runner: provider}) the example code above doesn't give a clue how can I save the typescript file. I assume some CLI command will do the trick. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hey @huseyindeniz .Notice how in the code you shared ERC20 is being imported directly in typescript. unlike with tools like typechain you don't even need to compile the contract with hardhat or generate any typescript. It "just works". See bundler docs here: https://tevm.sh/learn/solidity-imports/ |
Beta Was this translation helpful? Give feedback.
Yes the docs linked have a section on how to do code gen. But tldr simply run “npx tevm gen . /path/to/contract.sol
Note however this is the same thing as importing the file from a different package but extra steps. Importing doesn’t tightly couple code. Imports are by definition static, happening at build time not runtime, and explicitly using a package boundary