burnFrom
The burnFrom
function is an integral part of the StableCoin Contracts, enabling the burning of tokens from a specified user's account. This function is particularly useful in scenarios where tokens need to be removed from circulation in a controlled manner, often as part of staking, governance, or reward mechanisms. The operation is contingent upon having prior approval from the token owner, typically granted through the approve
method.
Method Signature
async burnFrom(from: string, amount: string, signer: any): Promise<string>
Parameters
from: string
: The Ethereum address from which the tokens will be burned. This can be a standard Ethereum address or an ENS name.amount: string
: The quantity of tokens to burn, represented as a string.signer: any
: An object representing the signer of the transaction, commonly sourced from a wallet interface like MetaMask or ethers.js.
Function Logic
- Resolve ENS Name: If the
from
address is an ENS name, it's resolved to its corresponding Ethereum address. - Get Contract Instance: Acquires a contract instance using the
signer
to interact with the blockchain. - Burn Transaction: Executes the
burnFrom
method on the contract with the resolvedfrom
address and the specifiedamount
. - Return Result: Outputs the result of the burn transaction, typically a transaction hash, as a string.
Example Usage
const fromAddress = "holder.eth";
const amount = "200";
const signer = ethersProvider.getSigner();
stableCoinContract.burnFrom(fromAddress, amount, signer)
.then(result =>
// add your logic here
)
.catch(error =>
// add your logic here
);
Notes
- The
burnFrom
method requires careful handling due to its ability to remove tokens from another user's account. - Proper formatting of the
amount
parameter is crucial to ensure successful and intended transaction execution.