-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,814 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# TypeChain x Web3 v1 example | ||
|
||
## Running | ||
|
||
```sh | ||
yarn # it will automatically run TypeChain types generation | ||
|
||
# yarn generate-types to manually regenerate them | ||
|
||
yarn start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "web3-v1", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"generate-types": "typechain --target=ethers-v4 'abi/*.json'", | ||
"postinstall": "yarn generate-types", | ||
"start": "ts-node ./src/index.ts", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@typechain/ethers-v4": "^1.0.0-beta", | ||
"@types/bn.js": "^4.11.6", | ||
"ts-node": "^8.8.2", | ||
"typechain": "^2.0.0-beta1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"ethers": "^4.0.47" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as ethers from 'ethers' | ||
import { Dai } from '../types/ethers-contracts/Dai' | ||
|
||
const abi = require('../abi/dai.json') | ||
|
||
const RPC_HOST = 'https://mainnet.infura.io/v3/6d6c70e65c77429482df5b64a4d0c943' | ||
const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F' | ||
|
||
async function main() { | ||
const provider = new ethers.providers.JsonRpcProvider(RPC_HOST) | ||
const formatEther = ethers.utils.formatEther | ||
|
||
const dai = (new ethers.Contract(DAI_ADDRESS, abi, provider) as any) as Dai | ||
const balance = await dai.functions.balanceOf('0x70b144972C5Ef6CB941A5379240B74239c418CD4') | ||
|
||
console.log(`Our DAI balance is: ${formatEther(balance)}`) | ||
|
||
dai.interface.events.Transfer | ||
} | ||
|
||
main().catch(e => { | ||
console.error(e) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2018", "DOM"], | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"target": "ES2018", | ||
"sourceMap": true, | ||
"esModuleInterop": true | ||
} | ||
} |
Oops, something went wrong.