Skip to content

Myrepo #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ func (c *Client) getKey() string {

// New initialize a new etherscan API client
// please use pre-defined network value
func New(network Network, APIKeys []string) *Client {
func New(network Network, APIKeys string) *Client {
return NewCustomized(Customization{
Timeout: 30 * time.Second,
Keys: []string{APIKeys},
BaseURL: fmt.Sprintf(`https://%s.etherscan.io/api?`, network.SubDomain()),
})
}

// New initialize a new etherscan API client
// please use pre-defined network value
func NewMultiKey(network Network, APIKeys []string) *Client {
return NewCustomized(Customization{
Timeout: 30 * time.Second,
Keys: APIKeys,
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestClient_craftURL(t *testing.T) {
c := New(Ropsten, []string{"abc123"})
c := New(Ropsten, "abc123")

const expected = `https://api-ropsten.etherscan.io/api?action=craftURL&apikey=abc123&four=d&four=e&four=f&module=testing&one=1&three=1&three=2&three=3&two=2`
output := c.craftURL("testing", "craftURL", M{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/nanmu42/etherscan-api
module github.com/NFEL/etherscan-api-multikey

go 1.13

Expand Down
3 changes: 2 additions & 1 deletion setup_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func init() {
}
bucket = NewBucket(500 * time.Millisecond)

api = New(Mainnet, []string{apiKey, backupApiKey})
api = New(Mainnet, apiKey)
api = NewMultiKey(Mainnet, []string{apiKey, backupApiKey})
api.Verbose = true
api.BeforeRequest = func(module string, action string, param map[string]interface{}) error {
bucket.Take()
Expand Down