initial ws server with lookupToken
This commit is contained in:
21
blockchain.js
Normal file
21
blockchain.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import {ethers} from "ethers";
|
||||
|
||||
const providers = {} // indexed by chain id
|
||||
|
||||
|
||||
export function provider(chainId) {
|
||||
let result = providers[chainId]
|
||||
if( result === undefined ) {
|
||||
const rpc_url = process.env['DEXORDER_RPC_URL_'+chainId]
|
||||
if( rpc_url === undefined ) {
|
||||
console.error('No provider found for chainId',chainId)
|
||||
return null
|
||||
}
|
||||
result = rpc_url.startsWith('ws') ?
|
||||
new ethers.WebSocketProvider(rpc_url, chainId) :
|
||||
new ethers.JsonRpcProvider(rpc_url, chainId)
|
||||
providers[chainId] = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user