Skip to content
Open
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
15 changes: 10 additions & 5 deletions util/EtherscanApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
const ETHERSCAN_URL = 'https://api.etherscan.io/api?'
const ETHERSCAN_URL = 'https://api.etherscan.io/v2/api'
const ETHERSCAN_CHAIN_ID = process.env.ETHERSCAN_CHAIN_ID || '1'

export async function etherscanRequest(
module: string,
action: string,
params: object,
) {
const query: any = {
apikey: process.env.APIKEY_ETHERSCAN,
const query: Record<string, string> = {
chainid: ETHERSCAN_CHAIN_ID,
apikey: process.env.APIKEY_ETHERSCAN || '',
module: module,
action: action,
...params,
}

const url = ETHERSCAN_URL + new URLSearchParams(query)
Object.entries(params).forEach(([key, value]) => {
query[key] = String(value)
})

const url = `${ETHERSCAN_URL}?${new URLSearchParams(query)}`
return fetch(url)
}

Expand Down
4 changes: 3 additions & 1 deletion util/EtherscanParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function etherscanParse(
response: EtherscanResponse,
): EtherscanContractResponse {
if (response.message !== 'OK') {
throw 'etherscan response is not OK'
const reason =
typeof response.result === 'string' ? response.result : response.message
throw `etherscan response is not OK: ${reason}`
}

if (!response.result || response.result.length == 0) {
Expand Down