initial ws server with lookupToken

This commit is contained in:
Tim Olson
2023-08-28 20:25:49 -04:00
commit 2a0133e605
7 changed files with 341 additions and 0 deletions

21
blockchain.js Normal file
View 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
}