This contract is a sample implementation of the Soroban token interface. It provides functionalities for token minting, setting administrators, managing allowances, transferring tokens, burning tokens, and retrieving token metadata such as name, symbol, and decimals.
To deploy and interact with this contract, you will need to set up a Soroban environment and have access to the Soroban SDK.
- Function:
initialize
- Purpose: Initializes the token contract with the provided parameters, including the administrator address, decimal precision, token name, and symbol.
- Access: Only callable once during contract initialization.
- Parameters:
admin
: Address of the administrator.decimal
: Decimal precision for token amounts.name
: Name of the token.symbol
: Symbol of the token.
- Function:
mint
- Purpose: Mints new tokens and assigns them to a specified account.
- Access: Only callable by the administrator.
- Parameters:
to
: Address of the recipient.amount
: Amount of tokens to mint.
- Function:
set_admin
- Purpose: Sets a new administrator for the token contract.
- Access: Only callable by the current administrator.
- Parameters:
new_admin
: Address of the new administrator.
- Function:
allowance
- Purpose: Retrieves the amount of tokens that the spender is allowed to spend on behalf of the owner.
- Parameters:
from
: Address of the owner of the tokens.spender
: Address of the spender.
- Function:
approve
- Purpose: Approves the spender to spend a specified amount of tokens on behalf of the owner.
- Access: Only callable by the owner of the tokens.
- Parameters:
spender
: Address of the spender.amount
: Amount of tokens to approve.expiration_ledger
: Expiration ledger for the approval.
- Function:
balance
- Purpose: Retrieves the token balance of a specified account.
- Parameters:
id
: Address of the account.
- Function:
transfer
- Purpose: Transfers tokens from one account to another.
- Access: Only callable by the owner of the tokens.
- Parameters:
from
: Address of the sender.to
: Address of the recipient.amount
: Amount of tokens to transfer.
- Function:
transfer_from
- Purpose: Transfers tokens from one account to another on behalf of the owner.
- Access: Only callable by the approved spender.
- Parameters:
spender
: Address of the spender.from
: Address of the owner of the tokens.to
: Address of the recipient.amount
: Amount of tokens to transfer.
- Function:
burn
- Purpose: Burns a specified amount of tokens from the owner's account.
- Access: Only callable by the owner of the tokens.
- Parameters:
from
: Address of the token owner.amount
: Amount of tokens to burn.
- Function:
burn_from
- Purpose: Burns a specified amount of tokens on behalf of the owner.
- Access: Only callable by the approved spender.
- Parameters:
spender
: Address of the spender.from
: Address of the token owner.amount
: Amount of tokens to burn.
- Functions:
decimals
: Retrieves the decimal precision of the token.name
: Retrieves the name of the token.symbol
: Retrieves the symbol of the token.
The contract provides unit tests for certain functionalities, including allowance-related functions. These tests can be run using the appropriate testing framework.
This contract depends on the Soroban SDK and related modules such as admin
, allowance
, balance
, and metadata
. Ensure that these dependencies are properly installed and configured before deploying the contract.