-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgetting-started.spec.ts
75 lines (67 loc) · 1.93 KB
/
getting-started.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { shepherd } from '@src/';
import { IProviderConfig } from '@src/ducks/providerConfigs/types';
const myProviderConfig: IProviderConfig = {
// size of the worker pool / maximum concurrent requests
concurrency: 4,
network: 'ETH',
// how many failures before provider is considered offline
requestFailureThreshold: 3,
// supported methods to pass on to the provider to process
supportedMethods: {
getNetVersion: true,
ping: true,
sendCallRequest: true,
sendCallRequests: true,
getBalance: true,
estimateGas: true,
getTransactionCount: true,
getCurrentBlock: true,
sendRawTx: true,
getCode: true,
getTransactionByHash: true,
getTransactionReceipt: true,
/*web3 methods*/
signMessage: true,
sendTransaction: true,
},
// maximum time until a request is considered timed out
timeoutThresholdMs: 5000,
};
async function main() {
// initialize the balancer, returning a provider singleton instance to use throughout your application
const provider = await shepherd.init({
network: 'ETH', // the network for the balancer to use
providerCallRetryThreshold: 4, // how many times a rpc call will be retried until its considered a failed call
});
// add a provider to be used with the balancer
shepherd.useProvider(
'rpc',
'myLocalParityNode',
myProviderConfig,
'http://localhost:8545',
);
// add a second provider to be balanced with on the same network "ETH"
shepherd.useProvider(
'rpc',
'myLocalParityNode2',
myProviderConfig,
'http://localhost:8546',
);
// make an rpc call
console.log(
await provider
.getBalance('0x829BD824B016326A401d083B33D092293333A830')
.then(
result =>
`Balance of 0x829BD824B016326A401d083B33D092293333A830: ${result}`,
)
.catch(err => `Getting balance failed due to ${err.message}`),
);
}
it(
'should work',
async () => {
await main();
},
7000,
);