-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1334 from denbite/rpc_failover
Introduce `FailoverRpcProvider` that switches between providers in case of a failure of one of them
- Loading branch information
Showing
12 changed files
with
737 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@near-js/accounts": minor | ||
"@near-js/providers": minor | ||
"@near-js/wallet-account": minor | ||
--- | ||
|
||
Introduce FailoverRpcProvider that switches between providers in case of a failure of one of them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// demonstrates how to use multiple providers with different API-KEYs | ||
const { providers } = require('near-api-js'); | ||
|
||
const RPC_API_ENDPOINT_1 = '<Replace this string with your RPC server URL>'; | ||
const API_KEY_1 = '<Replace this string with your API KEY>'; | ||
|
||
const RPC_API_ENDPOINT_2 = '<Replace this string with another RPC server URL>'; | ||
const API_KEY_2 = '<Replace this string with another API KEY>'; | ||
|
||
const jsonProviders = [ | ||
new providers.JsonRpcProvider({ | ||
url: RPC_API_ENDPOINT_1, | ||
headers: { 'x-api-key': API_KEY_1 }, | ||
}), | ||
new providers.JsonRpcProvider({ | ||
url: RPC_API_ENDPOINT_2, | ||
headers: { 'x-api-key': API_KEY_2 }, | ||
}), | ||
]; | ||
const provider = new providers.FailoverRpcProvider(jsonProviders); | ||
|
||
getNetworkStatus(); | ||
|
||
async function getNetworkStatus() { | ||
const result = await provider.status(); | ||
console.log(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FailoverRpcProvider } from '@near-js/providers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.