alchemy_getTokenAllowance
Returns the amount which the spender is allowed to withdraw from the owner.

Parameters

  1. 1.
    Object - An object with the following fields:
    • contract: DATA, 20 Bytes - The address of the token contract.
    • owner: DATA, 20 Bytes - The address of the token owner.
    • spender: DATA, 20 Bytes - The address of the token spender.

Returns

String - The allowance amount.

Example

Request

Alchemy Web3
Fetch (JS)
Axios (JS)
Curl
Postman
1
// alchemy-token-api/alchemy-web3-script.js
2
import { createAlchemyWeb3 } from "@alch/alchemy-web3";
3
4
// Replace with your Alchemy api key:
5
const apiKey = "demo";
6
7
// Initialize an alchemy-web3 instance:
8
const web3 = createAlchemyWeb3(
9
`https://eth-mainnet.g.alchemy.com/v2/${apiKey}`,
10
);
11
12
const allowance = await web3.alchemy.getTokenAllowance({contract: "0xE41d2489571d322189246DaFA5ebDe1F4699F498", owner: "0xe8095A54C83b069316521835408736269bfb389C", spender:"0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db"})
13
14
console.log("TOKEN ALLOWANCE->");
15
console.log(allowance);
Copied!
1
import fetch from 'node-fetch';
2
3
var requestOptions = {
4
method: 'GET',
5
redirect: 'follow'
6
};
7
8
const baseURL = "https://eth-mainnet.g.alchemy.com/v2/demo/getTokenAllowance/";
9
10
// replace with the respective address you want to query for
11
const contractAddr = "0xE41d2489571d322189246DaFA5ebDe1F4699F498";
12
const ownerAddr = "0xe8095A54C83b069316521835408736269bfb389C";
13
const spenderAddr = "0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db";
14
const fetchURL = `${baseURL}?contract=${contractAddr}?owner=${ownerAddr}?spender=${spenderAddr}`;
15
16
fetch(fetchURL, requestOptions)
17
.then(response => response.json())
18
.then(response => JSON.stringify(response, null, 2))
19
.then(result => console.log(result))
20
.catch(error => console.log('error', error))
Copied!
1
import axios from 'axios';
2
3
// replace with your Alchemy api key
4
const apiKey = "demo";
5
const baseURL = `https://eth-mainnet.g.alchemy.com/v2/${apiKey}/getNFTs/`;
6
7
// replace with the respective address you want to query for
8
cconst contractAddr = "0xE41d2489571d322189246DaFA5ebDe1F4699F498";
9
const ownerAddr = "0xe8095A54C83b069316521835408736269bfb389C";
10
const spenderAddr = "0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db";
11
12
var config = {
13
method: 'get',
14
url: `${baseURL}?contract=${contractAddr}?owner=${ownerAddr}?spender=${spenderAddr}`
15
};
16
17
axios(config)
18
.then(response => console.log(JSON.stringify(response.data, null, 2)))
19
.catch(error => console.log(error));
20
Copied!
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"alchemy_getTokenAllowance","params":[{"contract":"0xE41d2489571d322189246DaFA5ebDe1F4699F498", "owner":"0xe8095A54C83b069316521835408736269bfb389C", "spender":"0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db"}],"id": 1}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"alchemy_getTokenAllowance",
7
"params":[{"contract":"0xE41d2489571d322189246DaFA5ebDe1F4699F498", "owner":"0xe8095A54C83b069316521835408736269bfb389C", "spender":"0x3Bcc5bD4abBc853395eBE5103b7DbA20411E38db"}],
8
"id":83
9
}
Copied!

Result

1
{
2
"jsonrpc": "2.0",
3
"id": 83,
4
"result": "10963536149943846000",
5
}
Copied!