Fungible tokens
Quick start
from pynear.account import Account
from pynear.dapps.fts import FTS
import asyncio
ACCOUNT_ID = "bob.near"
PRIVATE_KEY = "ed25519:..."
async def main():
acc = Account(ACCOUNT_ID, PRIVATE_KEY)
await acc.startup()
# send 5 USDC to azbang.near
tr = await acc.ft.transfer(FTS.USDC, "azbang.near", 5, force_register=True)
print(tr.transaction.hash)
asyncio.run(main())
Documentation
- class FT(DappClient)
Client to any NEP-141 contract` With this contract you can send fungible tokens to any user
acc = Account(...) ft = acc.ft await acc.ft.transfer(FTS.USDC, "azbang.near", 5, force_register=True)
- get_ft_balance(ft: FtModel, account_id: str)
Get fungible token balance
- Parameters:
ft – fungible token model FT.USDC
account_id – account id
- Returns:
amount // 10**ft.decimal
await acc.ft.get_ft_balance(FTS.USDC, account_id="azbang.near")
- get_metadata(ft: FtModel, account_id: str)
Get fungible token metadata
- Parameters:
ft – fungible token model FT.USDC
- Returns:
FtTokenMetadata
await acc.ft.get_metadata(FTS.USDC)
- transfer(ft: FtModel, account_id: str, amount: float, memo: str = '', force_register: bool = False)
Transfer fungible token to account
- Parameters:
ft – fungible token model FT.USDC
receiver_id – receiver account id
amount – float amount to transfer. 1 for 1 USDC
memo – comment
force_register – use storage_deposit() if account is not registered
nowait – if nowait is True, return transaction hash, else wait execution
- Returns:
transaction hash or TransactionResult
await acc.ft.transfer(FTS.USDC, "azbang.near", 5, force_register=True)
- transfer_call(ft: FtModel, account_id: str, amount: float, memo: str = '', force_register: bool = False, nowait: bool = False)
Transfer fungible token to account and call ft_on_transfer() method in receiver contract
- Parameters:
ft – fungible token model FT.USDC
receiver_id – receiver account id
amount – float amount to transfer. 1 for 1 USDC
memo – comment
force_register – use storage_deposit() if account is not registered
nowait – if nowait is True, return transaction hash, else wait execution
- Returns:
transaction hash or TransactionResult
await acc.ft.transfer_call(FTS.USDC, "azbang.near", 5, force_register=True)
- storage_balance_of(ft: FtModel, account_id: str)
Get storage balance of account. The balance must be greater than 0.01 NEAR for some smart contracts in order for the recipient to accept the token
- Parameters:
contract_id – fungible token contract_id
account_id – account id
- Returns:
int balance in yoctoNEAR, 1_000_000_000_000_000_000_000_000 for 1 NEAR
await acc.ft.storage_balance_of(FTS.USDC, "azbang.near")
- storage_deposit(ft: FtModel, account_id: str, amount: int = NEAR // 50)
Deposit storage balance for account. The balance must be greater than 0.01 NEAR for some smart contracts
- Parameters:
ft – fungible token model FT.USDC
account_id – receiver account id
amount – in amount of yoctoNEAR
- Returns:
await acc.ft.storage_deposit(FTS.USDC, "azbang.near")