Enhanced Web3 API

Alchemy offers several enhanced API methods on top of the existing web3.js calls.

To learn more about the standard web3.js API calls, check out their documentation here.

β€‹πŸ˜Ž Enhanced API Calls

web3.alchemy.getTokenAllowance({contract, owner, spender})

Returns token balances for a specific address given a list of contracts.

Parameters:

An object with the following fields:

  • contract: The address of the token contract.

  • owner: The address of the token owner.

  • spender: The address of the token spender.

Returns:

The allowance amount, as a string representing a base-10 number.

web3.alchemy.getTokenBalances(address, contractAddresses)

Returns token balances for a specific address given a list of contracts.

Parameters:

  1. address: The address for which token balances will be checked.

  2. contractAddresses: An array of contract addresses.

Returns:

An object with the following fields:

  • address: The address for which token balances were checked.

  • tokenBalances: An array of token balance objects. Each object contains:

    • contractAddress: The address of the contract.

    • tokenBalance: The balance of the contract, as a string representing a base-10 number.

    • error: An error string. One of this or tokenBalance will be null.

web3.alchemy.getTokenMetadata(address)

Returns metadata (name, symbol, decimals, logo) for a given token contract address.

Parameters:

address: The address of the token contract.

Returns:

An object with the following fields:

  • name: The token's name. null if not defined in the contract and not available from other sources.

  • symbol: The token's symbol. null if not defined in the contract and not available from other sources.

  • decimals: The token's decimals. null if not defined in the contract and not available from other sources.

  • logo: URL of the token's logo image. null if not available.

web3.eth.subscribe("alchemy_fullPendingTransactions")

Subscribes to pending transactions, similar to the standard Web3 call web3.eth.subscribe("pendingTransactions"), but differs in that it emits full transaction information rather than just transaction hashes.

Note that the argument passed to this function is "alchemy_fullPendingTransactions", which is different from the string used in raw eth_subscribe JSON-RPC calls, where it is "alchemy_newFullPendingTransactions" instead. This is confusing, but it is also consistent with the existing Web3 subscription APIs (for example: web3.eth.subscribe("pendingTransactions") vs "newPendingTransactions" in raw JSON-RPC).