diff --git a/src/utils.ts b/src/utils.ts index 3d4b8797e..7ec5f37cc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -10,7 +10,7 @@ import addFormats from 'ajv-formats'; import addErrors from 'ajv-errors'; import Multicaller from './utils/multicaller'; import { getSnapshots } from './utils/blockfinder'; -import getProvider from './utils/provider'; +import getProvider, { setBroviderUrl } from './utils/provider'; import { signMessage, getBlockNumber } from './utils/web3'; import { getHash, verify } from './verify'; import gateways from './gateways.json'; @@ -786,6 +786,7 @@ export default { sleep, getNumberWithOrdinal, voting, + setBroviderUrl, getProvider, signMessage, getBlockNumber, diff --git a/src/utils/provider.ts b/src/utils/provider.ts index efbf39f64..37c271a4c 100644 --- a/src/utils/provider.ts +++ b/src/utils/provider.ts @@ -10,7 +10,10 @@ export type ProviderOptions = { broviderUrl?: string; }; -const DEFAULT_BROVIDER_URL = 'https://rpc.snapshot.org'; +let DEFAULT_BROVIDER_URL = 'https://rpc.snapshot.org'; +export function setBroviderUrl(broviderUrl: string) { + DEFAULT_BROVIDER_URL = broviderUrl; +} export default function getProvider( network, diff --git a/test/provider.ts b/test/provider.ts new file mode 100644 index 000000000..350761e72 --- /dev/null +++ b/test/provider.ts @@ -0,0 +1,9 @@ +const snapshot = require('../'); + +const provider_DEFAULT = snapshot.utils.getProvider('1'); +console.log(provider_DEFAULT.connection.url == 'https://rpc.snapshot.org/1'); + +snapshot.utils.setBroviderUrl('https://rpc.custom.org'); +const provider_CUSTOM = snapshot.utils.getProvider('56'); +console.log(provider_CUSTOM.connection.url == 'https://rpc.custom.org/56'); +