Skip to content

Etherscan V2 #1388

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 3 commits into from
May 15, 2025
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
10 changes: 10 additions & 0 deletions .changeset/violet-students-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@xchainjs/xchain-evm-providers': patch
'@xchainjs/xchain-arbitrum': patch
'@xchainjs/xchain-ethereum': patch
'@xchainjs/xchain-avax': patch
'@xchainjs/xchain-base': patch
'@xchainjs/xchain-bsc': patch
---

Support etherscan v2
12 changes: 6 additions & 6 deletions packages/xchain-arbitrum/__e2e__/arbitrum.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@ const TestnetUSDCAsset: TokenAsset = {

describe('Arbitrum', () => {
it('should fetch Arbitrum balances', async () => {
const address = testnetClient.getAddress(0)
const address = '0x46545017fa98CA2efeF277c90B4c0044ca913596'
console.log(address)
const balances = await testnetClient.getBalance(address)
const balances = await mainnetClient.getBalance(address, [])
balances.forEach((bal: Balance) => {
console.log(`${assetToString(bal.asset)} = ${bal.amount.amount()}`)
})
expect(balances.length).toBeGreaterThan(0)
})
it('should fetch arbitrum txs', async () => {
const address = '0x007ab5199b6c57f7aa51bc3d0604a43505501a0c'
const txPage = await testnetClient.getTransactions({ address })
const txPage = await mainnetClient.getTransactions({ address })
console.log(JSON.stringify(txPage, null, 2))
expect(txPage.total).toBeGreaterThan(0)
expect(txPage.txs.length).toBeGreaterThan(0)
})
it('should fetch arbitrum erc20 txs', async () => {
const address = '0xe77872fb49750e6ae361fc13aa67397637ddcf5d'
const txPage = await testnetClient.getTransactions({ address, asset: '0x179522635726710dd7d2035a81d856de4aa7836c' })
const address = '0x9f0b60CD0FCfE9828a92c2F6f6E6B4Cf8DAb003a'
const txPage = await mainnetClient.getTransactions({ address, asset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' })
console.log(JSON.stringify(txPage, null, 2))
expect(txPage.total).toBeGreaterThan(0)
expect(txPage.txs.length).toBeGreaterThan(0)
})
it('should fetch arbitrum transfer transaction', async () => {
const txId = '0x1c3b135fe8f108b57973aee6f567aca4219ae5ec903461ac427d6ea71d25f3fb'
const txId = '0x11bbb59714a8056e2af018692f6153b0514514fe9b9edd23d94d4220821159da'
const tx = await testnetClient.getTransactionData(txId)
console.log(JSON.stringify(tx, null, 2))
const amount = assetToBase(assetAmount('0.001', 18))
Expand Down
17 changes: 10 additions & 7 deletions packages/xchain-arbitrum/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import necessary modules and classes from external packages and files
import { ExplorerProvider, Network } from '@xchainjs/xchain-client'
import { EVMClientParams } from '@xchainjs/xchain-evm'
import { EtherscanProvider } from '@xchainjs/xchain-evm-providers'
import { EtherscanProviderV2 } from '@xchainjs/xchain-evm-providers'
import { Asset, AssetType, TokenAsset } from '@xchainjs/xchain-util'
import { BigNumber, ethers } from 'ethers'

Expand All @@ -23,6 +23,7 @@ export const AssetARB: TokenAsset = {
}

// Define JSON-RPC providers for mainnet and testnet
// Ankr api key
const ARBITRUM_MAINNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider('https://arb1.arbitrum.io/rpc')
const ARBITRUM_TESTNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider('https://goerli-rollup.arbitrum.io/rpc')

Expand All @@ -34,22 +35,24 @@ const ethersJSProviders = {
}

// Define online providers (Etherscan) for mainnet and testnet
const ARB_ONLINE_PROVIDER_MAINNET = new EtherscanProvider(
const ARB_ONLINE_PROVIDER_MAINNET = new EtherscanProviderV2(
ARBITRUM_MAINNET_ETHERS_PROVIDER,
'https://api.arbiscan.io',
process.env.ARBISCAN_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
ARBChain,
AssetAETH,
18,
42161,
)

const ARB_ONLINE_PROVIDER_TESTNET = new EtherscanProvider(
const ARB_ONLINE_PROVIDER_TESTNET = new EtherscanProviderV2(
ARBITRUM_TESTNET_ETHERS_PROVIDER,
'https://api-goerli.arbiscan.io',
process.env.ARBISCAN_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
ARBChain,
AssetAETH,
18,
421614,
)

// Define providers for different networks
Expand Down
69 changes: 35 additions & 34 deletions packages/xchain-avax/__e2e__/avax-client.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Balance, Network, TxType } from '@xchainjs/xchain-client'
import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '@xchainjs/xchain-evm'
import { CovalentProvider, EvmOnlineDataProvider } from '@xchainjs/xchain-evm-providers'
import { AssetType, TokenAsset, assetAmount, assetToBase, assetToString, baseAmount } from '@xchainjs/xchain-util'

import AvaxClient from '../src'
Expand All @@ -17,46 +16,48 @@ const assetRIP: TokenAsset = {
type: AssetType.TOKEN,
}

const AVAX_ONLINE_PROVIDER_TESTNET = new CovalentProvider(
process.env.COVALENT_API_KEY as string,
AVAXChain,
43113,
AssetAVAX,
18,
)

const AVAX_ONLINE_PROVIDER_MAINNET = new CovalentProvider(
process.env.COVALENT_API_KEY as string,
AVAXChain,
43114,
AssetAVAX,
18,
)

const avaxProviders = {
[Network.Mainnet]: AVAX_ONLINE_PROVIDER_MAINNET,
[Network.Testnet]: AVAX_ONLINE_PROVIDER_TESTNET,
[Network.Stagenet]: AVAX_ONLINE_PROVIDER_MAINNET,
}

const fakeProviders = {
[Network.Mainnet]: {} as EvmOnlineDataProvider,
[Network.Testnet]: {} as EvmOnlineDataProvider,
[Network.Stagenet]: {} as EvmOnlineDataProvider,
}

defaultAvaxParams.network = Network.Testnet
// const AVAX_ONLINE_PROVIDER_TESTNET = new CovalentProvider(
// process.env.COVALENT_API_KEY as string,
// AVAXChain,
// 43113,
// AssetAVAX,
// 18,
// )

// const AVAX_ONLINE_PROVIDER_MAINNET = new CovalentProvider(
// process.env.COVALENT_API_KEY as string,
// AVAXChain,
// 43114,
// AssetAVAX,
// 18,
// )

// const avaxProviders = {
// [Network.Mainnet]: AVAX_ONLINE_PROVIDER_MAINNET,
// [Network.Testnet]: AVAX_ONLINE_PROVIDER_TESTNET,
// [Network.Stagenet]: AVAX_ONLINE_PROVIDER_MAINNET,
// }

// const fakeProviders = {
// [Network.Mainnet]: {} as EvmOnlineDataProvider,
// [Network.Testnet]: {} as EvmOnlineDataProvider,
// [Network.Stagenet]: {} as EvmOnlineDataProvider,
// }

defaultAvaxParams.network = Network.Mainnet
defaultAvaxParams.phrase = process.env.TESTNET_PHRASE
// eslint-disable-next-line @typescript-eslint/no-explicit-any
defaultAvaxParams.dataProviders = [fakeProviders as any, avaxProviders]
const client = new AvaxClient(defaultAvaxParams)
// defaultAvaxParams.dataProviders = [fakeProviders as any, avaxProviders]
const client = new AvaxClient({
...defaultAvaxParams,
})

function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
describe('xchain-evm (Avax) Integration Tests', () => {
it('should fetch avax balances', async () => {
const address = await client.getAddressAsync(0)
const address = '0x09383137C1eEe3E1A8bc781228E4199f6b4A9bbf'
console.log(address)
const balances = await client.getBalance(address)
balances.forEach((bal: Balance) => {
Expand All @@ -72,7 +73,7 @@ describe('xchain-evm (Avax) Integration Tests', () => {
expect(txPage.txs.length).toBeGreaterThan(0)
})
it('should fetch single avax transfer tx', async () => {
const txId = '0x206d2300e57d0c23e48b8c4cc4af9c87abf33e2f406ac2265915b3d7b0e131e2'
const txId = '0x4dab51e68d03df97aaf3c8fd9afa3026f6ca7531f79b11a0c0ed39df6d0119e9'
const tx = await client.getTransactionData(txId)
console.log(JSON.stringify(tx, null, 2))
const amount = assetToBase(assetAmount('0.01', 18))
Expand Down
25 changes: 17 additions & 8 deletions packages/xchain-avax/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import necessary modules and classes from external packages and files
import { ExplorerProvider, Network } from '@xchainjs/xchain-client'
import { EVMClientParams } from '@xchainjs/xchain-evm'
import { EtherscanProvider, RoutescanProvider } from '@xchainjs/xchain-evm-providers'
import { EtherscanProviderV2, RoutescanProvider } from '@xchainjs/xchain-evm-providers'
import { Asset, AssetType } from '@xchainjs/xchain-util'
import { BigNumber, ethers } from 'ethers'

Expand All @@ -19,8 +19,15 @@ const ankrApiKey = process.env.ANKR_API_KEY
// Define JSON-RPC providers for mainnet and testnet
const AVALANCHE_MAINNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider(
`https://rpc.ankr.com/avalanche/${ankrApiKey}`,
{ name: 'avalanche', chainId: 43114 },
)
const AVALANCHE_TESTNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider(
`https://rpc.ankr.com/avalanche_fuji/${ankrApiKey}`,
{
name: 'fuji',
chainId: 43113,
},
)
const AVALANCHE_TESTNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider('https://rpc.ankr.com/avalanche_fuji')

// Define ethers providers for different networks
const ethersJSProviders = {
Expand All @@ -30,21 +37,23 @@ const ethersJSProviders = {
}

// Define online providers (Etherscan) for mainnet and testnet
const AVAX_ONLINE_PROVIDER_TESTNET = new EtherscanProvider(
const AVAX_ONLINE_PROVIDER_TESTNET = new EtherscanProviderV2(
AVALANCHE_TESTNET_ETHERS_PROVIDER,
'https://api-testnet.snowtrace.io',
process.env.SNOWTRACE_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
AVAXChain,
AssetAVAX,
18,
43113,
)
const AVAX_ONLINE_PROVIDER_MAINNET = new EtherscanProvider(
const AVAX_ONLINE_PROVIDER_MAINNET = new EtherscanProviderV2(
AVALANCHE_MAINNET_ETHERS_PROVIDER,
'https://api.snowtrace.io',
process.env.SNOWTRACE_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
AVAXChain,
AssetAVAX,
18,
43114,
)

// Define providers for different networks
Expand Down
4 changes: 2 additions & 2 deletions packages/xchain-base/__e2e__/base.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mainnetClient = new BaseClient({
const testnetClient = new BaseClient({
...defaultBaseParams,
phrase: process.env.TESTNET_PHRASE,
network: Network.Mainnet,
network: Network.Testnet,
})

const MainnetUSDTAsset: TokenAsset = {
Expand All @@ -40,7 +40,7 @@ describe('Base', () => {
it('should fetch Base balances', async () => {
const address = testnetClient.getAddress(0)
console.log(address)
const balances = await testnetClient.getBalance('0x585142ebBA458B681caea61Bb178E529EdAd23f4')
const balances = await testnetClient.getBalance('0x537b2331DdaA849e62756ab7d32A6749e83443aE', [])
balances.forEach((bal: Balance) => {
console.log(`${assetToString(bal.asset)} = ${bal.amount.amount()}`)
})
Expand Down
16 changes: 9 additions & 7 deletions packages/xchain-base/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import necessary modules and classes from external packages and files
import { ExplorerProvider, Network } from '@xchainjs/xchain-client'
import { EVMClientParams } from '@xchainjs/xchain-evm'
import { EtherscanProvider } from '@xchainjs/xchain-evm-providers'
import { EtherscanProviderV2 } from '@xchainjs/xchain-evm-providers'
import { Asset, AssetType } from '@xchainjs/xchain-util'
import { BigNumber, ethers } from 'ethers'

Expand All @@ -26,22 +26,24 @@ const ethersJSProviders = {
}

// Define online providers (Etherscan) for mainnet and testnet
const BASE_ONLINE_PROVIDER_MAINNET = new EtherscanProvider(
const BASE_ONLINE_PROVIDER_MAINNET = new EtherscanProviderV2(
BASE_MAINNET_ETHERS_PROVIDER,
'https://api.basescan.org',
process.env.BASE_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
BASEChain,
AssetBETH,
18,
8453,
)

const BASE_ONLINE_PROVIDER_TESTNET = new EtherscanProvider(
const BASE_ONLINE_PROVIDER_TESTNET = new EtherscanProviderV2(
BASE_TESTNET_ETHERS_PROVIDER,
'https://api-sepolia.basescan.org',
process.env.BASE_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
BASEChain,
AssetBETH,
18,
84532,
)

// Define providers for different networks
Expand Down
4 changes: 2 additions & 2 deletions packages/xchain-bsc/__e2e__/bsc-client.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ describe('xchain-evm (Bsc) Integration Tests', () => {
expect(assetInfo).toEqual(correctAssetInfo)
})
it('should fetch bsc balances', async () => {
const address = await clientTestnet.getAddressAsync(0)
const address = "0x1a3d9D7A717D64e6088aC937d5aAcDD3E20ca963"
console.log(address)
const balances = await clientTestnet.getBalance(address)
const balances = await clientTestnet.getBalance(address, [])
balances.forEach((bal: Balance) => {
console.log(`${assetToString(bal.asset)} = ${bal.amount.amount()}`)
})
Expand Down
16 changes: 9 additions & 7 deletions packages/xchain-bsc/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { ExplorerProvider, Network } from '@xchainjs/xchain-client' // Importing ExplorerProvider and Network from xchain-client
import { EVMClientParams } from '@xchainjs/xchain-evm' // Importing EVMClientParams from xchain-evm
import { EtherscanProvider } from '@xchainjs/xchain-evm-providers' // Importing EtherscanProvider from xchain-evm-providers
import { EtherscanProviderV2 } from '@xchainjs/xchain-evm-providers' // Importing EtherscanProvider from xchain-evm-providers
import { Asset, AssetType } from '@xchainjs/xchain-util' // Importing Asset from xchain-util
import { BigNumber, ethers } from 'ethers' // Importing BigNumber and ethers from ethers library

Expand Down Expand Up @@ -49,21 +49,23 @@ const ethersJSProviders = {
}

// ONLINE providers
const BSC_ONLINE_PROVIDER_TESTNET = new EtherscanProvider(
const BSC_ONLINE_PROVIDER_TESTNET = new EtherscanProviderV2(
BSC_TESTNET_ETHERS_PROVIDER,
'https://api-testnet.bscscan.com',
process.env.BSCSCAN_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
BSCChain,
AssetBSC,
BSC_GAS_ASSET_DECIMAL,
97,
)
const BSC_ONLINE_PROVIDER_MAINNET = new EtherscanProvider(
const BSC_ONLINE_PROVIDER_MAINNET = new EtherscanProviderV2(
BSC_MAINNET_ETHERS_PROVIDER,
'https://api.bscscan.com',
process.env.BSCSCAN_API_KEY || '',
'https://api.etherscan.io/v2',
process.env.ETHERSCAN_API_KEY || '',
BSCChain,
AssetBSC,
BSC_GAS_ASSET_DECIMAL,
56,
)
const bscProviders = {
[Network.Mainnet]: BSC_ONLINE_PROVIDER_MAINNET,
Expand Down
4 changes: 2 additions & 2 deletions packages/xchain-ethereum/__e2e__/eth-client.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function delay(ms: number) {
}
describe('xchain-evm (Eth) Integration Tests', () => {
it('should fetch eth balances', async () => {
const address = '0x26000cc95ab0886FE8439E53c73b1219Eba9DBCF'
const address = '0xBCB883aB7f1cAFC8C6C5fa7F5aF9d064cCE73AC1'
console.log(address)
const balances = await clientTestnet.getBalance(address)
const balances = await clientTestnet.getBalance(address, [])
balances.forEach((bal: Balance) => {
console.log(`${assetToString(bal.asset)} = ${bal.amount.amount()}`)
})
Expand Down
Loading