forked from sebs/etherscan-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.ts
More file actions
41 lines (38 loc) · 1.25 KB
/
Client.ts
File metadata and controls
41 lines (38 loc) · 1.25 KB
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
import { account } from './actions/account'
import { ClientAccountBalance } from './client/ClientAccountBalance'
import { ClientAccountBalancemulti } from './client/ClientAccountBalancemulti'
import { Address } from './entities/Address'
import { ApiKey } from './entities/Apikey'
/**
* Client for the api at etherscan.io
*/
export class Client {
/**
* Api key to access the etherscan api
*/
private apiKey: ApiKey
constructor(apiKey: string) {
this.apiKey = new ApiKey(apiKey)
this.apiKey.validate()
}
/**
* methods to access ethereum accounts
* @param action
*/
account(action: string): any {
if (!account.get(action)) {
throw new Error('unknown action')
}
const actions: { [key: string]: any } = {
balance: (address: string, tag: string): ClientAccountBalance => {
const oAddress = new Address(address)
return new ClientAccountBalance(this.apiKey, 'account', action, oAddress, tag)
},
balancemulti(address: string[], tag: string): ClientAccountBalancemulti {
const oAddress = address.map((addresString) => new Address(addresString))
return new ClientAccountBalancemulti(this.apiKey, 'account', action, oAddress, tag)
},
}
return actions[action]
}
}