@@ -19,16 +19,16 @@ export async function GET(req: NextRequest) {
1919 try {
2020 switch ( apiType ) {
2121 case 'etherscan' :
22- apiUrl = `https://api.etherscan.io/api?address=${ address } &apikey=${ ETHERSCAN_API_KEY } &module=account&action=txlist ` ;
22+ apiUrl = `https://api.etherscan.io/v2/ api?module=account&action=txlist& address=${ address } &chainid=1& apikey=${ ETHERSCAN_API_KEY } ` ;
2323 break ;
2424 case 'base-sepolia' :
25- apiUrl = `https://api-sepolia.basescan.org/ api?address=${ address } &apikey=${ BASESCAN_API_KEY } &module=account&action=txlistinternal ` ;
25+ apiUrl = `https://api.etherscan.io/v2/ api?module=account&action=txlistinternal& address=${ address } &chainid=84532& apikey=${ ETHERSCAN_API_KEY } ` ;
2626 break ;
2727 case 'basescan' :
28- apiUrl = `https://api.basescan.org/ api?address=${ address } &apikey=${ BASESCAN_API_KEY } &module=account&action=txlist ` ;
28+ apiUrl = `https://api.etherscan.io/v2/ api?module=account&action=txlist& address=${ address } &chainid=8453& apikey=${ ETHERSCAN_API_KEY } ` ;
2929 break ;
3030 case 'basescan-internal' :
31- apiUrl = `https://api.basescan.org/ api?address=${ address } &apikey=${ BASESCAN_API_KEY } &module=account&action=txlistinternal ` ;
31+ apiUrl = `https://api.etherscan.io/v2/ api?module=account&action=txlistinternal& address=${ address } &chainid=8453& apikey=${ ETHERSCAN_API_KEY } ` ;
3232 break ;
3333 default :
3434 return NextResponse . json ( { error : 'Invalid apiType parameter' } , { status : 400 } ) ;
@@ -43,13 +43,32 @@ export async function GET(req: NextRequest) {
4343 } ) ;
4444
4545 const contentType = externalResponse . headers . get ( 'content-type' ) ;
46+ const maskedApiUrl = apiUrl . replace ( / ( a p i k e y = ) [ ^ & ] + / i, '$1****' ) ;
4647 let responseData ;
4748 if ( contentType ?. includes ( 'application/json' ) ) {
4849 responseData = await externalResponse . json ( ) ;
4950 } else {
5051 responseData = await externalResponse . text ( ) ;
5152 }
5253
54+ // Log upstream V1 deprecation warnings safely (masked URL)
55+ try {
56+ const maybeJson = typeof responseData === 'string' ? JSON . parse ( responseData ) : responseData ;
57+ if (
58+ maybeJson ?. status === '0' &&
59+ typeof maybeJson ?. message === 'string' &&
60+ maybeJson . message . toLowerCase ( ) . includes ( 'deprecated' )
61+ ) {
62+ console . warn ( '[api/proxy] Upstream API deprecation warning' , {
63+ apiType,
64+ apiUrl : maskedApiUrl ,
65+ message : maybeJson . message ,
66+ } ) ;
67+ }
68+ } catch {
69+ // ignore non-JSON bodies
70+ }
71+
5372 if ( externalResponse . ok ) {
5473 return NextResponse . json ( { data : responseData } ) ;
5574 } else {
0 commit comments