Skip to content

Commit

Permalink
Add iconURL to chains
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Jun 7, 2024
1 parent 64f883f commit c38a24c
Show file tree
Hide file tree
Showing 9 changed files with 3,940 additions and 1,142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-update-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: yarn
Expand Down
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Helper module for getting EVM chain info from [chainid.network](https://chainid.network/).

Note: This package was initially created by @taylorjdawson. We forked the repository so we can control the release process with an automated script. The original package can be found [here](https://github.com/taylorjdawson/eth-chains).
Note: This package was initially created by @taylorjdawson. We forked the repository so we can control the release process with an automated script and make additional changes. The original package can be found [here](https://github.com/taylorjdawson/eth-chains).

## Installation

Expand All @@ -21,17 +21,7 @@ yarn add @revoke.cash/chains
Import `chains` methods and enums:

```ts
import chains, { ChainId, ChainName } from '@revoke.cash/chains'
```

### Easily get most popular chains:

```ts
import { chain } from '@revoke.cash/chains'

console.log(chain.ethereum.rinkeby)

console.log(chain.polygon.mumbai)
import allChains, { ChainId, ChainName } from '@revoke.cash/chains'
```

### Chain names and ids via Enums:
Expand All @@ -46,30 +36,30 @@ console.log(ChainName.Rinkeby) // "Rinkeby"
### Chain by ID:

```ts
chains.getById(ChainId.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
getChainById(ChainId.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
// Equivalent
chains.getById(1)
getChainById(1)
```

### Chain by Name:

```ts
chains.getByName(ChainName.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
getChainByName(ChainName.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
// Equivalent
chains.getByName('Ethereum Mainnet')
getChainByName('Ethereum Mainnet')
```

### Get all Chains:

```ts
const allChains = chains.all()
const chains = allChains()
// { 1: { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }, 2: {...}}
```

### Typescript Types:

```ts
import { Chain, NativeCurrency, Explorer } from '@revoke.cash/chains'
const ethereum: Chain = chains.getById(ChainId.EthereumMainnet)
const ethereum: Chain = getChainById(ChainId.EthereumMainnet)
ethereum.chain // 'ETH'
```
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@revoke.cash/chains",
"version": "43.0.0",
"version": "44.0.0",
"description": "Helper module for getting EVM chains info.",
"author": "Revoke.cash",
"contributors": [
Expand All @@ -16,7 +16,7 @@
"license": "MIT",
"scripts": {
"build": "tsc",
"generate": "ts-node src/build.ts",
"generate": "tsx src/build.ts",
"format": "prettier --write src/",
"prepack": "yarn build"
},
Expand All @@ -25,7 +25,7 @@
"@types/prettier": "^2.2.3",
"got": "^11.8.2",
"prettier": "^2.2.1",
"ts-node": "^9.1.1",
"tsx": "^4.13.1",
"typescript": "^4.2.3"
},
"publishConfig": {
Expand Down
20 changes: 19 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ const generateEnumFile = async (chains: Chain[]) => {
}

const generateChainsFile = async () => {
const chains: Chain[] = await got(
const initialChains: Chain[] = await got(
'https://chainid.network/chains.json'
).json()

const chains = await annotateIconUrls(initialChains)

await generateEnumFile(chains).catch(() => {
console.log('Error generating enum file')
})
Expand All @@ -67,4 +69,20 @@ const generateChainsFile = async () => {
)
}

const annotateIconUrls = async (chains: Chain[]) => {
return Promise.all(
chains.map(async chain => {
if (!chain.icon) return chain;

const [icon] = await got(
`https://raw.githubusercontent.com/ethereum-lists/chains/master/_data/icons/${chain.icon}.json`
).json<Array<{ url: string }>>();

const iconURL = icon?.url?.replace('ipfs://', 'https://cloudflare-ipfs.com/ipfs/')

return { ...chain, iconURL }
})
);
};

generateChainsFile()
Loading

0 comments on commit c38a24c

Please sign in to comment.