Skip to content

Commit

Permalink
Merge pull request #36 from scio-labs/feat/28-support-all-ink-compati…
Browse files Browse the repository at this point in the history
…ble-chains

feat: Add support for all ink!-compatible chains
  • Loading branch information
wottpal authored Oct 21, 2023
2 parents aee5f09 + a69c625 commit 10a37eb
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-panthers-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@scio-labs/use-inkathon': minor
---

Added native support for more !ink compatible testnets (t0rn, Bit.Country, Peaq, Pendulum, Phala) and mainnets (Khala, Phala, Amplitude, Pendulum)
172 changes: 148 additions & 24 deletions src/chains.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
/**
* Substrate Chain Type
*/
export interface SubstrateChain {
network: string
name: string
rpcUrls: [string, ...string[]]
ss58Prefix?: number
explorerUrls?: Partial<Record<SubstrateExplorer, string>>
testnet?: boolean
faucetUrls?: string[]
}

export enum SubstrateExplorer {
Subscan = 'subscan',
PolkadotJs = 'polkadotjs',
}
import { SubstrateChain, SubstrateExplorer } from '@/types'

/**
* Defined Substrate Chain Constants
* Local Development Network
*/

/// Local Development Network
export const development: SubstrateChain = {
network: 'development',
name: 'Local Development',
Expand All @@ -35,7 +18,9 @@ export const development: SubstrateChain = {
faucetUrls: ['https://polkadot.js.org/apps/#/accounts?rpc=ws://127.0.0.1:9944'],
}

/// Testnets
/**
* Live Testnets
*/

export const alephzeroTestnet: SubstrateChain = {
network: 'alephzero-testnet',
Expand All @@ -53,7 +38,8 @@ export const alephzeroTestnet: SubstrateChain = {

export const rococo: SubstrateChain = {
network: 'rococo',
name: 'Rococo',
name: 'Rococo Contracts Testnet',
ss58Prefix: 42,
rpcUrls: ['wss://rococo-contracts-rpc.polkadot.io'],
explorerUrls: {
[SubstrateExplorer.Subscan]: `https://rococo.subscan.io`,
Expand All @@ -74,7 +60,80 @@ export const shibuya: SubstrateChain = {
faucetUrls: ['https://portal.astar.network/#/shibuya-testnet/assets'],
}

/// Canary Networks (Kusama)
export const t0rnTestnet: SubstrateChain = {
network: 't0rn',
name: 'T0rn Testnet',
ss58Prefix: 42,
rpcUrls: ['wss://ws.t0rn.io'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://ws.t0rn.io',
)}/#/explorer`,
},
testnet: true,
faucetUrls: ['https://faucet.t0rn.io'],
}

export const bitCountryAlphaTestnet: SubstrateChain = {
network: 'bitcountry-alpha-testnet',
name: 'Bit.Country Alpha Testnet',
ss58Prefix: 268,
rpcUrls: ['wss://alphanet-rpc-gcp.bit.country'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://alphanet-rpc-gcp.bit.country',
)}#/explorer`,
},
testnet: true,
faucetUrls: ['https://testnet.bit.country/p/wallet/balance'],
}

export const agungTestnet: SubstrateChain = {
network: 'agung-testnet',
name: 'Agung Testnet',
ss58Prefix: 42,
rpcUrls: ['wss://wss.agung.peaq.network'],
explorerUrls: {
[SubstrateExplorer.Subscan]: `https://agung-testnet.subscan.io/`,
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://wss.agung.peaq.network',
)}/#/explorer`,
},
testnet: true,
faucetUrls: ['https://discord.com/channels/943486047625572392/963415793394143232'],
}

export const amplitudeTestnet: SubstrateChain = {
network: 'amplitude-testnet',
name: 'Amplitude Testnet',
ss58Prefix: 57,
rpcUrls: ['wss://pencol-roc-00.pendulumchain.tech'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://pencol-roc-00.pendulumchain.tech',
)}/#/explorer`,
},
testnet: true,
faucetUrls: [],
}

export const phalaPOC5Testnet: SubstrateChain = {
network: 'phala-PoC-5-testnet',
name: 'Phala PoC-5 Testnet',
ss58Prefix: 30,
rpcUrls: ['wss://poc5.phala.network/ws'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://poc5.phala.network/ws',
)}#/explorer`,
},
testnet: true,
faucetUrls: [],
}

/**
* Live Canary Networks
*/

export const shiden: SubstrateChain = {
network: 'shiden',
Expand All @@ -86,7 +145,39 @@ export const shiden: SubstrateChain = {
},
}

/// Mainnets
export const amplitude: SubstrateChain = {
network: 'amplitude',
name: 'Amplitude',
ss58Prefix: 57,
rpcUrls: ['wss://rpc-amplitude.pendulumchain.tech', 'wss://amplitude-rpc.dwellir.com'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://rpc-amplitude.pendulumchain.tech',
)}#/explorer`,
},
}

export const khala: SubstrateChain = {
network: 'khala',
name: 'Khala',
ss58Prefix: 30,
rpcUrls: [
'wss://khala-api.phala.network/ws',
'wss://khala.api.onfinality.io/public-ws',
'wss://khala-rpc.dwellir.com',
'wss://public-rpc.pinknode.io/khala',
],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://khala-api.phala.network/ws',
)}#/explorer`,
[SubstrateExplorer.Subscan]: `https://khala.subscan.io`,
},
}

/**
* Live Mainnet Networks
*/

export const alephzero: SubstrateChain = {
network: 'alephzero',
Expand All @@ -109,7 +200,31 @@ export const astar: SubstrateChain = {
explorerUrls: {
[SubstrateExplorer.Subscan]: `https://astar.subscan.io`,
},
faucetUrls: [],
}

export const pendulum: SubstrateChain = {
network: 'pendulum',
name: 'Pendulum',
ss58Prefix: 56,
rpcUrls: ['wss://rpc-pendulum.prd.pendulumchain.tech', 'wss://pendulum-rpc.dwellir.com'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://rpc-pendulum.prd.pendulumchain.tech',
)}#/explorer`,
},
}

export const phala: SubstrateChain = {
network: 'phala',
name: 'Phala',
ss58Prefix: 30,
rpcUrls: ['wss://api.phala.network/ws', 'wss://phala.api.onfinality.io/public-ws'],
explorerUrls: {
[SubstrateExplorer.PolkadotJs]: `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(
'wss://api.phala.network/ws',
)}#/explorer`,
[SubstrateExplorer.Subscan]: `https://phala.subscan.io`,
},
}

/**
Expand All @@ -119,10 +234,19 @@ export const allSubstrateChains: SubstrateChain[] = [
development,
alephzeroTestnet,
rococo,
t0rnTestnet,
bitCountryAlphaTestnet,
agungTestnet,
amplitudeTestnet,
phalaPOC5Testnet,
shibuya,
shiden,
amplitude,
khala,
alephzero,
astar,
pendulum,
phala,
]

/**
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/initPolkadotJs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SubstrateChain } from '@/chains'
import { SubstrateChain } from '@/types'
import { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api'
import { ApiOptions } from '@polkadot/api/types'

Expand Down
5 changes: 3 additions & 2 deletions src/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { accountArraysAreEqual, accountsAreEqual, initPolkadotJs } from '@/helpers'
import { registerDeployments } from '@/registry'
import {
SubstrateChain,
SubstrateDeployment,
SubstrateWallet,
UseInkathonError,
UseInkathonErrorCode,
Expand All @@ -18,8 +20,7 @@ import { ApiOptions } from '@polkadot/api/types'
import { InjectedAccount, InjectedExtension, Unsubcall } from '@polkadot/extension-inject/types'
import { Signer } from '@polkadot/types/types'
import { FC, PropsWithChildren, createContext, useContext, useEffect, useState } from 'react'
import { SubstrateChain, getSubstrateChain } from './chains'
import { SubstrateDeployment } from './types/SubstrateDeployment'
import { getSubstrateChain } from './chains'

const UseInkathonProviderContext = createContext<UseInkathonProviderContextType | null>(null)

Expand Down
17 changes: 17 additions & 0 deletions src/types/SubstrateChain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Substrate Chain Type
*/
export interface SubstrateChain {
network: string
name: string
rpcUrls: [string, ...string[]]
ss58Prefix?: number
explorerUrls?: Partial<Record<SubstrateExplorer, string>>
testnet?: boolean
faucetUrls?: string[]
}

export enum SubstrateExplorer {
Subscan = 'subscan',
PolkadotJs = 'polkadotjs',
}
2 changes: 1 addition & 1 deletion src/types/UseInkathonProviderContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SubstrateWallet } from '@/types'
import { SubstrateChain } from '@/types/SubstrateChain'
import { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api'
import { InjectedAccount, InjectedExtension } from '@polkadot/extension-inject/types'
import { Signer } from '@polkadot/types/types'
import { Dispatch, SetStateAction } from 'react'
import { SubstrateChain } from '../chains'
import { SubstrateDeployment } from './SubstrateDeployment'

export type UseInkathonProviderContextType = {
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @index('./*.ts', f => `export * from '${f.path}'`)
export * from './ChainAsset'
export * from './SubstrateChain'
export * from './SubstrateDeployment'
export * from './SubstrateWallet'
export * from './UseInkathonProviderContext'
Expand Down

0 comments on commit 10a37eb

Please sign in to comment.