getAllowance
The getAllowance
method determines the amount of tokens an owner has permitted another Ethereum address to expend on their behalf. This method often finds use in tandem with token approvals, especially in scenarios such as granting a smart contract the capability to move tokens on one's behalf. The method is an attribute of the ERC20Instance
object, derived from the getERC20Instance
function of the EdexaClient
.
Method Signature
getAllowance(owner: string, spender: string): Promise<BigNumber>
Parameters
Parameter | Type | Description |
---|---|---|
owner | string | The Ethereum address of the token proprietor. |
spender | string | The Ethereum address of the party authorized to utilize tokens on the owner's account. |
Returns
- A
Promise
that unravels to aBigNumber
, illustrating the quantity of tokens that thespender
can withdraw from theowner
.
Usage Example
To begin, instantiate the intended ERC20 token contract with its designated address:
const erc20 = edexaClient.getERC20Instance("0x4DB67190e915C15aA8CCd889F35185D73dA37878");
Subsequently, invoke the getAllowance
method, supplying the Ethereum addresses of the token owner and the spender:
const ownerAddress = "0xF6E234C71F1bB45ABa51c977137eF090b2df2Fe5";
const spenderAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const allowance = await erc20.getAllowance(ownerAddress, spenderAddress);
console.log(`Allowance: ${allowance.toString()}`);
Notes
The divulged allowance will be in the most fractional unit of the ERC20 token (like Wei for Ether). Depending on the token's decimals, you might need to translate this value into a format more easily understood by humans.
An allowance value of
0
signifies that thespender
currently lacks permission to transfer any tokens in the name of theowner
.