Nhảy đến nội dung chính

Balance changes

Các điều kiện tiên quyết

Native NEAR (Ⓝ)

Balance changes on accounts can be tracked by using our changes RPC endpoint. You can test this out by sending tokens to an account using NEAR-CLI and then viewing the changes made.

Send Tokens

near send sender.testnet receiver.testnet 1
  • Bạn sẽ thấy một kết quả trong terminal của mình trông giống như sau:
Sending 1 NEAR to receiver.testnet from sender.testnet
Transaction Id 4To336bYcoGc3LMucJPMk6fMk5suKfCrdNotrRtTxqDy
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/4To336bYcoGc3LMucJPMk6fMk5suKfCrdNotrRtTxqDy

View Balance Changes

Ví dụ Query sử dụng HTTPie:

http post https://rpc.testnet.near.org jsonrpc=2.0 id=dontcare \
method=EXPERIMENTAL_changes \
'params:={
"block_id": "CJ24svU3C9FaULVjcNVnWuVZjK6mNaQ8p6AMyUDMqB37",
"changes_type": "account_changes",
"account_ids": ["sender.testnet"]
}'
**Ví dụ về response nhận được:**
{
"id": "dontcare",
"jsonrpc": "2.0",
"result": {
"block_hash": "BRgE4bjmUo33jmiVBcZaWGkSLVeL7TTi4ZxYTvJdPbB9",
"changes": [
{
"cause": {
"tx_hash": "4To336bYcoGc3LMucJPMk6fMk5suKfCrdNotrRtTxqDy",
"type": "transaction_processing"
},
"change": {
"account_id": "sender.testnet",
"amount": "11767430014412510000000000",
"code_hash": "11111111111111111111111111111111",
"locked": "0",
"storage_paid_at": 0,
"storage_usage": 806
},
"type": "account_update"
}
]
}
}

Ngoài ra, bạn có thể xem số dư của account bằng cách truy vấn view_account mà chỉ yêu cầu một accountId.

Ví dụ HTTPie Request:

http post https://rpc.testnet.near.org jsonrpc=2.0 id=dontcare method=query \
params:='{
"request_type": "view_account",
"finality": "final",
"account_id": "sender.testnet"
}'

Ví dụ về response nhận được là:

{
"id": "dontcare",
"jsonrpc": "2.0",
"result": {
"amount": "11767430683960197500000000",
"block_hash": "HUiscpNyoyR5z1UdnZhAJLNz1G8UjBrFTecSYqCrvdfW",
"block_height": 50754977,
"code_hash": "11111111111111111111111111111111",
"locked": "0",
"storage_paid_at": 0,
"storage_usage": 806
}
}

Note: Gas prices can change between blocks. Even for transactions with deterministic gas cost the cost in NEAR could also be different. You can query the gas price for recent blocks using the gas_price RPC endpoint.