alchemyplatform/alchemy-web3

Property 'contractAddress' does not exist on type 'TokenBalance'

Closed this issue · 1 comments

I got this error in my editor after trying to get token balance.
The result after calling API look like this.

const balances: TokenBalancesResponse = {
address: <owner_address>,
tokenBalances: [
{
contractAddress: '0xBCa9c16d41BF2b9AE42f96d240015c8B5cb22DB7',
tokenBalance: '7973019999999999999879',
error: null
}
]
}

Then I tried to get tokenBalances[0].contractAddress but the editor alert that this property does not exist.
When I check types.ts in your source below, it shows only property address.

/// from your api [src/alchemy-apis/types.ts]

export interface TokenBalancesResponse {
address: string;
tokenBalances: TokenBalance[];
}

export type TokenBalance = TokenBalanceSuccess | TokenBalanceFailure;

export interface TokenBalanceSuccess {
address: string;
tokenBalance: string;
error: null;
}

@supachaic Thanks for catching and flagging this. You're correct in that the TokenBalanceSuccess and TokenBalanceFailure interfaces should have contractAddress instead of address as the property. Will have this fixed in an upcoming release.