Skip to content

Commit

Permalink
feat: upgrade to ethers v6
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Feb 5, 2023
1 parent b432596 commit 93a4a8b
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 841 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ npm install @hzhu/eth-balances
## Usage

```typescript
import { JsonRpcProvider } from "ethers";
import { getTokenBalances } from "@hzhu/eth-balances";
import { JsonRpcProvider } from "@ethersproject/providers";

const provider = new JsonRpcProvider(`https://YOUR-ETHEREUM-RPC-URL`);
const addressOrName = "henryzhu.eth";
Expand Down
5 changes: 2 additions & 3 deletions examples/node/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { StaticJsonRpcProvider } = require("@ethersproject/providers");
const { getAddress } = require("@ethersproject/address");
const { getAddress, JsonRpcProvider } = require("ethers");
const { getTokenBalances } = require("../../dist/index.cjs");

const RPC_URL =
"https://polygon-mainnet.g.alchemy.com/v2/2ZulmRPm8Kklt6G--5tqJn50WOP5lQCt";
const TOKEN_LIST = "https://api-polygon-tokens.polygon.technology/tokenlists/popularTokens.tokenlist.json";

const main = async () => {
const provider = new StaticJsonRpcProvider(RPC_URL);
const provider = new JsonRpcProvider(RPC_URL);
const addressOrName = "0x8a6BFCae15E729fd1440574108437dEa281A9B3e";
const response = await fetch(TOKEN_LIST);
const tokenList = await response.json();
Expand Down
10 changes: 4 additions & 6 deletions examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Ethereum Balances</title>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="module">
import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/5.6.9/ethers.esm.min.js";
import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.0.2/ethers.min.js";
import { getTokenBalances } from "./index.esm.js";
window.ethers = ethers;
window.getTokenBalances = getTokenBalances;
Expand All @@ -18,8 +18,7 @@
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
></script>
<script type="text/babel">
const { utils, providers } = ethers;
const { getAddress } = utils;
const { getAddress, Contract, JsonRpcProvider } = ethers;
const { useState } = React;
const container = document.querySelector("#root");
const root = ReactDOM.createRoot(container);
Expand All @@ -29,8 +28,7 @@
const RPC_URL =
"https://eth-mainnet.g.alchemy.com/v2/kKnqutLMseA48OflV2pFw2krgqapTPP8";
const TOKEN_LIST = "https://tokens.coingecko.com/uniswap/all.json";
const { StaticJsonRpcProvider } = providers;
const provider = new StaticJsonRpcProvider(RPC_URL);
const provider = new JsonRpcProvider(RPC_URL);

function App() {
const [balances, setBalances] = useState();
Expand All @@ -40,7 +38,7 @@
<div style={{ padding: "24px" }}>
<button
disabled={balances || loading}
style={{ fontSize: '24px', cursor: 'pointer' }}
style={{ fontSize: "24px", cursor: "pointer" }}
onClick={async () => {
setError("");
setLoading(true);
Expand Down
Loading

0 comments on commit 93a4a8b

Please sign in to comment.