Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethers v6 target #803

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tidy-readers-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'example-ethers-v6': major
'@typechain/ethers-v6': major
'@typechain/ethers-v6-test': major
---

Add ethers-v6 target
19 changes: 19 additions & 0 deletions examples/ethers-v6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# TypeChain x Ethers-v5 example

Note: examples in this dir require building monorepo first

```sh
# in the root of monorepo
pnpm i
pnpm build
```

## Running

```sh
pnpm install # it will automatically run TypeChain types generation

# pnpm generate-types to manually regenerate them

pnpm start
```
277 changes: 277 additions & 0 deletions examples/ethers-v6/abi/dai.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
[

{
"inputs": [{ "internalType": "uint256", "name": "chainId_", "type": "uint256" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "src", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "guy", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "Approval",
"type": "event"
},
{
"anonymous": true,
"inputs": [
{ "indexed": true, "internalType": "bytes4", "name": "sig", "type": "bytes4" },
{ "indexed": true, "internalType": "address", "name": "usr", "type": "address" },
{ "indexed": true, "internalType": "bytes32", "name": "arg1", "type": "bytes32" },
{ "indexed": true, "internalType": "bytes32", "name": "arg2", "type": "bytes32" },
{ "indexed": false, "internalType": "bytes", "name": "data", "type": "bytes" }
],
"name": "LogNote",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "src", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "dst", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "DOMAIN_SEPARATOR",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "PERMIT_TYPEHASH",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "address", "name": "", "type": "address" }
],
"name": "allowance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "burn",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }],
"name": "deny",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "mint",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "src", "type": "address" },
{ "internalType": "address", "name": "dst", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "move",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "nonces",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "holder", "type": "address" },
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "nonce", "type": "uint256" },
{ "internalType": "uint256", "name": "expiry", "type": "uint256" },
{ "internalType": "bool", "name": "allowed", "type": "bool" },
{ "internalType": "uint8", "name": "v", "type": "uint8" },
{ "internalType": "bytes32", "name": "r", "type": "bytes32" },
{ "internalType": "bytes32", "name": "s", "type": "bytes32" }
],
"name": "permit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "pull",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "push",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }],
"name": "rely",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "dst", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "transfer",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "src", "type": "address" },
{ "internalType": "address", "name": "dst", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "version",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "wards",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
22 changes: 22 additions & 0 deletions examples/ethers-v6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "example-ethers-v6",
"private": true,
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"scripts": {
"generate-types": "typechain --target=ethers-v6 'abi/*.json'",
"start": "ts-node ./src/index.ts",
"typecheck": "pnpm generate-types && tsc --noEmit"
},
"devDependencies": {
"@typechain/ethers-v6": "workspace:^1.0.0",
"@types/bn.js": "^5.1.0",
"ts-node": "^10.7.0",
"typechain": "workspace:^8.1.1",
"typescript": "^4.7"
},
"dependencies": {
"ethers": "^6.0.2"
}
}
29 changes: 29 additions & 0 deletions examples/ethers-v6/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { ethers } from 'ethers'

import { Dai__factory } from '../types/ethers-contracts/factories/Dai__factory'

const RPC_HOST = 'https://mainnet.infura.io/v3/6d6c70e65c77429482df5b64a4d0c943'
const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const BLOCK_NUMBER = 13730326

async function main() {
const provider = new ethers.JsonRpcProvider(RPC_HOST)
const dai = Dai__factory.connect(DAI_ADDRESS, provider)
const balance = await dai.balanceOf('0x70b144972C5Ef6CB941A5379240B74239c418CD4')

console.log(`Our DAI balance is: ${ethers.formatEther(balance)}`)

console.log(`Listing Transfer events for block ${BLOCK_NUMBER}`)
const eventsFilter = dai.filters.Transfer()
const events = await dai.queryFilter(eventsFilter, BLOCK_NUMBER, BLOCK_NUMBER)

for (const event of events) {
console.log(`${event.args.src} -> ${event.args.dst} | ${ethers.formatEther(event.args.wad)} DAI`)
}
}

main().catch((e) => {
console.error(e)
process.exit(1)
})
12 changes: 12 additions & 0 deletions examples/ethers-v6/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"lib": ["ES2018", "DOM"],
"module": "CommonJS",
"moduleResolution": "node16",
"strict": true,
"target": "ES2018",
"sourceMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
}
}
Loading