Staking
Note
Class to stake NEAR on liquid staking. You can stake NEAR and withdraw at any time without fees
Read more about staking: https://docs.herewallet.app/technology-description/readme
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()
transaction = await acc.staking.stake(10000)
print(tr.transaction.hash)
transaction = await acc.staking.receive_dividends()
print(tr.logs)
transaction = await acc.staking.unstake(10000)
print(tr.transaction.hash)
asyncio.run(main())
Documentation
- class Staking(DappClient)
Client to storage.herewallet.near contract With this contract you can stake NEAR without blocking and receive passive income ~9% APY
acc = Account(...) staking = acc.staking
- class StakingData(DappClient)
- apy_value: int
current APY value * 100 (908=9.08%)
- last_accrual_ts: int
Last UTC timestamp of accrued recalc
- accrued: int
Total accrued in yoctoNEAR, which can be receiver by receive_dividends() call
- transfer(account_id: str, amount: int, memo: str = '', force_register: bool = False)
Transfer hNEAR to account
- Parameters:
receiver_id – receiver account id
amount – amount in yoctoNEAR
memo – comment
:param nowait if True, method will return before transaction is confirmed :return: transaction hash ot TransactionResult
await acc.staking.transfer("azbang.near", 10000)
- transfer_call(account_id: str, amount: int, memo: str = '', force_register: bool = False)
Transfer hNEAR to account and call on_transfer_call() on receiver smart contract
- Parameters:
receiver_id – receiver account id
amount – amount in yoctoNEAR
memo – comment
:param nowait if True, method will return before transaction is confirmed :return: transaction hash ot TransactionResult
await acc.staking.transfer_call("azbang.near", 10000)
- get_staking_amount(account_id: str)
Get staking balance of account.
- Parameters:
account_id – account id
:param nowait if True, method will return before transaction is confirmed :return: int balance in yoctoNEAR
amount = await acc.staking.get_staking_amount("azbang.near") print(amount)
- get_user(account_id: str)
Get user staking parameters
- Parameters:
account_id – account id
- Returns:
StakingData
data = await acc.staking.get_user("azbang.near") print(data.apy_value / 100)
- stake(amount: int, nowait: bool = False)
Deposit staking for account
- Parameters:
amount – in amount of yoctoNEAR
nowait – if True, method will return before transaction is confirmed
- Returns:
transaction hash or TransactionResult
res = await acc.staking.stake(1_000_000_000_000_000) print(res.transaction.hash)
- unstake(amount: int, nowait: bool = False)
Withdraw from staking
- Parameters:
amount – in amount of yoctoNEAR
nowait – if True, method will return before transaction is confirmed
- Returns:
transaction hash or TransactionResult
res = await acc.staking.unstake(1_000_000_000_000_000) print(res.transaction.hash)
- receive_dividends(nowait: bool = False)
Receive dividends. user.accrued yoctoNEAR amount will transfer to staking balance
- Parameters:
nowait – if True, method will return before transaction is confirmed
- Returns:
transaction hash ot TransactionResult
res = await acc.staking.receive_dividends() print(res.transaction.hash)