Erc20
The Erc20
class from the @moonup/moon-api
package provides methods to interact with ERC-20 tokens.
Initialization
To use the Erc20
class, you need to create an instance of it by passing an instance of the HttpClient
class to its constructor. The HttpClient
class is also part of the @moonup/moon-api
package and provides a convenient way to make HTTP requests.
Here's an example of how to create an instance of the Erc20
class:
Methods
The Erc20
class provides the following methods:
allowanceErc20(name: string, data: InputBody, params?: RequestParams): Promise<AllowanceErc20Data>
Retrieves the amount of tokens that an owner has allowed to be spent by a spender.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
AllowanceErc20Data
.
Example usage:
approveErc20(name: string, data: InputBody, params?: RequestParams): Promise<ApproveErc20Data>
Approves a spender to spend a certain amount of tokens on behalf of the owner.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
ApproveErc20Data
.
Example usage:
balanceOfErc20(name: string, data: InputBody, params?: RequestParams): Promise<BalanceOfErc20Data>
Retrieves the balance of a specific account for a given ERC-20 token.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
BalanceOfErc20Data
.
Example usage:
decimalsErc20(name: string, data: InputBody, params?: RequestParams): Promise<DecimalsErc20Data>
Retrieves the number of decimals used by a given ERC-20 token.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
DecimalsErc20Data
.
Example usage:
nameErc20(name: string, data: InputBody, params?: RequestParams): Promise<NameErc20Data>
Retrieves the name of a given ERC-20 token.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
NameErc20Data
.
Example usage:
symbolErc20(name: string, data: InputBody, params?: RequestParams): Promise<SymbolErc20Data>
Retrieves the symbol of a given ERC-20 token.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
SymbolErc20Data
.
Example usage:
totalSupplyErc20(name: string, data: InputBody, params?: RequestParams): Promise<TotalSupplyErc20Data>
Retrieves the total supply of a given ERC-20 token.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
TotalSupplyErc20Data
.
Example usage:
transferErc20(name: string, data: InputBody, params?: RequestParams): Promise<TransferErc20Data>
Transfers a certain amount of tokens from the sender's account to a recipient's account.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
TransferErc20Data
.
Example usage:
transferFromErc20(name: string, data: InputBody, params?: RequestParams): Promise<TransferFromErc20Data>
Transfers a certain amount of tokens from a sender's account to a recipient's account on behalf of the sender.
name
is a string that represents the name of the ERC-20 token.data
is an object of typeInputBody
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
TransferFromErc20Data
.
Example usage:
These methods can be used to perform various operations on ERC-20 tokens, such as checking token balances, approving spenders, transferring tokens, and more. The Erc20
class is a part of the @moonup/moon-api
package, which provides a convenient way to interact with the Moon API.
Last updated