burnFrom
The burnFrom
function enables a user or contract to destroy a specified quantity of tokens from another user's account. This action necessitates prior authorization from the token owner, typically granted through the approve
method. The ability to burn tokens from another user's account can be implemented within specific token contracts for particular use cases, such as staking or governance scenarios.
Function Signature
async burnFrom(from: string, amount: BigNumberish, signer: WalletSigner): Promise<string>
Parameters
from
string
The Ethereum address from which the tokens are to be burned.
amount
BigNumberish
The quantity of tokens to be burned, specified in the smallest unit of the token (e.g., Wei for Ether).
signer
WalletSigner
The wallet signer instance responsible for signing the burn transaction. Typically created with createWalletSigner
.
Returns
A
Promise
resolving to astring
, typically representing the transaction hash corresponding to the burn operation.
Example Usage
Assuming the appropriate token contract is already instantiated:
const fromAddress = "0xF39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
const burnAmount = "1000000000000000000"; // Representing 1 token, given an 18-decimal precision
const signer = zkyugaClient.createWalletSigner("your private key");
const transactionHash = await erc20.burnFrom(fromAddress, burnAmount, signer);
console.log(`Burn Transaction Hash: ${transactionHash}`);
Considerations
Prior to executing the
burnFrom
method, ensure that thefrom
address has granted sufficient allowance to thesigner
via theapprove
method.Remember that the
amount
is specified in the smallest divisible unit of the token. Accurate management of conversions is crucial.As a security precaution, safeguard the confidentiality of your private keys and exercise caution when using the
signer
in potentially insecure environments.
Last updated