NEAR CLI
near-cli
là một NodeJS command line interface sử dụngnear-api-js
để kết nối và tương tác với NEAR blockchain.
Tổng quan
Click vào từng command để xem thông tin chi tiết và các ví dụ.
Các Access Key
Command | Mô tả |
---|---|
near login | lưu trữ một full access key trong local bằng cách sử dụng NEAR Wallet |
near keys | hiển thị tất cả các access key và thông tin chi tiết của chúng cho một account nhất định |
near generate-key | tạo một cặp key local hoặc hiển thị public key & implicit account |
near add-key | thêm một access key mới vào account |
near delete-key | xóa một access key từ một account |
Các Account
Command | Mô tả |
---|---|
near create-account | tạo một account |
near state | hiển thị các thông tin chi tiết của account |
near keys | hiển thị tất cả các access key của một account nhất định |
near send | gửi các token từ một account này đến một account khác |
near delete | xóa account và chuyển số dư còn lại sang account thụ hưởng |
Các contract
Command | Mô tả |
---|---|
near deploy | deploy một smart contract lên NEAR blockchain |
near dev-deploy | tạo một development account và deploy contract trên account đó (testnet only) |
near call | tạo một contract call có thể thực thi các change hoặc view method |
near view | tạo một contract call chỉ có thể thực thi một view method |
near view-state | trả về state của contract (các cặp key/value) hoặc dưới dạng utf-8 hoặc borsh serialized |
Các transaction
Command | Mô tả |
---|---|
near tx-status | truy vấn status của một transaction bằng txHash |
Các validator
Command | Mô tả |
---|---|
near validators current | hiển thị chi tiết epoch validator pool hiện tại |
near validators next | hiển thị chi tiết validator cho epoch tiếp theo |
near proposals | hiển thị các validator proposal cho epoch tiếp theo sau |
REPL
Command | Mô tả |
---|---|
near repl | khởi chạy một kết nối tương tác với NEAR blockchain (REPL) |
Để được hỗ trợ EVM, xem thêm tại
aurora-cli
của Project Aurora.
Setup
Cài đặt
Đảm bảo rằng máy tính của bạn đã cài đặt phiên bản hiện tại của
npm
vàNodeJS
.
Mac và Linux
- Cài đặt
npm
vànode
bằng cách sử dụng một package manager nhưnvm
vì đôi khi có những sự cố khi sử dụng Ledger do cách OS X xử lý các node package có liên quan đến các thiết bị USB. [Nhấn vào đây] - Đảm bảo bạn đã cài đặt Node với version 12 trở lên.
- Cài đặt global
near-cli
bằng cách chạy:
npm install -g near-cli
Windows
Đối với người dùng Windows, chúng tôi khuyên bạn nên sử dụng Windows Subsystem for Linux (
WSL
).
- Cài đặt
WSL
[nhấn vào đây] - Cài đặt
npm
[nhấn vào đây] - Cài đặt
Node.js
[nhấn vào đây ] - Thay đổi thư mục
npm
mặc định [ nhấn vào đây ]- Điều này giúp tránh mọi vấn đề về quyền hạn với
WSL
- Điều này giúp tránh mọi vấn đề về quyền hạn với
- Mở
WSL
và cài đặt globalnear-cli
bằng cách chạy:
npm install -g near-cli
Chú ýCopy/paste có thể bị lỗi khi sử dụng
WSL
.
- "Quick Edit Mode" sẽ cho phép paste bằng việc click chuột phải.
- Tùy thuộc vào phiên bản của bạn, có thể có một checkbox khác cho phép paste bằng
Ctrl
+V
.
Another way for Windows users (not fully tested):
- Install node.js from https://nodejs.org/en/
- In cmd.exe run:
npm install -g near-cli
- Set enviroment variable:
set NEAR_ENV=YOURNETWORK
By deffault cli used Testnet
NOTE: in all comands with '{}' you need to replace spaces to \ in {}
Update near-cli
Nếu có một bản update
near-cli
khả dụng, bạn sẽ được thông báo trên terminal sau khi chạy bất kỳ lệnh nào. (xem ví dụ bên dưới)
- Làm theo các hướng dẫn để cập nhật bằng cách chạy dòng lệnh sau:
npm install -g near-cli
- Bạn luôn có thể kiểm tra phiên bản hiện tại của mình bằng cách chạy dòng lệnh sau:
near --version # version info appears on the last line of output
- Ngoài ra, bạn có thể xem phiên bản mới nhất hiện có bằng cách sử dụng
npm outdated
.
npm outdated -g # note the difference between Current and Latest
Troubleshooting:
Nếu bạn gặp bất kỳ vấn đề nào khi nâng cấp NEAR CLI, cách nhanh nhất để giải quyết vấn đề là gỡ cài đặt rồi cài đặt lại.
npm uninstall -g near-cli
npm install -g near-cli
Network selection
Network mặc định cho
near-cli
làtestnet
.
- Bạn có thể thay đổi network bằng cách thêm một environment variable vào command của mình.
NEAR_ENV=betanet near send ...
- Ngoài ra, bạn có thể thiết lập một environment variable chung bằng cách chạy đoạn code sau:
export NEAR_ENV=mainnet
Access Keys
near login
lưu trữ toàn bộ access key trên local của account bạn đã tạo với NEAR Wallet.
- các tham số:
không
- các tuỳ chọn:
mặc định
Example:
near login
- Bạn sẽ được điều hướng đến NEAR Wallet yêu cầu toàn bộ quyền truy cập vào account của bạn.
- Tiếp theo, hãy chọn account bạn muốn có một access key.
- Sau khi bạn click vào
allow
, bạn sẽ được yêu cầu xác nhận sự ủy quyền này bằng cách nhập tên account.
Vị trí Access Key:
Sau khi hoàn tất, bạn sẽ có Access Key của mình được lưu trữ trong local trong một thư mục ẩn được gọi là
.near-credentials
- Thư mục này nằm ở root của thư mục
HOME
:~/.near-credentials
(MAC / Linux)C:\Users\YOUR_ACCOUNT\.near-credentials
(Windows)
- Thư mục này nằm ở root của thư mục
Bên trong
.near-credentials
, các access key được tổ chức trong các thư mục con của network:default
chotestnet
betanet
mainnet
Các thư mục con network này chứa các object
.JSON
với:account_id
private_key
public_key
Example:
{
"account_id": "example-acct.testnet",
"public_key": "ed25519:7ns2AZVaG8XZrFrgRw7g8qhgddNTN64Zkz7Eo8JBnV5g",
"private_key": "ed25519:4Ijd3vNUmdWJ4L922BxcsGN1aDrdpvUHEgqLQAUSLmL7S2qE9tYR9fqL6DqabGGDxCSHkKwdaAGNcHJ2Sfd"
}
near keys
Hiển thị tất cả các access key cho một account nhất định.
- các tham số:
accountId
- các tuỳ chọn:
mặc định
Example:
near keys client.chainlink.testnet
Example Response:
Keys for account client.chainlink.testnet
[
{
public_key: 'ed25519:4wrVrZbHrurMYgkcyusfvSJGLburmaw7m3gmCApxgvY4',
access_key: { nonce: 97, permission: 'FullAccess' }
},
{
public_key: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
access_key: {
nonce: 88,
permission: {
FunctionCall: {
allowance: '18483247987345065500000000',
receiver_id: 'client.chainlink.testnet',
method_names: [ 'get_token_price', [length]: 1 ]
}
}
}
},
[length]: 2
]
near generate-key
Tạo một cặp local key trong
.near-credentials
hoặc hiển thị public key từ Ledger hoặc seed phrase.
- các tham số:
accountId
hoặckhông có
- các tuỳ chọn:
--useLedgerKey
,--seedPhrase
, or--seedPath
Note: There are several ways to use generate-key
that return very different results. Please reference the examples below for further details.
1) near generate-key
Tạo một cặp local key trong
.near-credentials
với một implicit account như là accountId. (đại diện hash của public key)
near generate-key
**Ví dụ response nhận được là:**
Key pair with ed25519:33Vn9VtNEtWQPPd1f4jf5HzJ5weLcvGHU8oz7o5UnPqy public key for an account "1e5b1346bdb4fc5ccd465f6757a9082a84bcacfd396e7d80b0c726252fe8b3e8"
2) near generate-key accountId
Tạo một cặp local key trong
.near-credentials
với mộtaccountId
mà bạn chỉ định.
Note: This does NOT create an account with this name, and will overwrite an existing .json
file with the same name.
near generate-key example.testnet
**Example Response:**
Key pair with ed25519:CcH3oMEFg8tpJLekyvF7Wp49G81K3QLhGbaWEFwtCjht public key for an account "example.testnet"
3a) near generate-key --useLedgerKey
Sử dụng một thiết bị Ledger đã được kết nối để hiển thị public key và implicit account sử dụng đường dẫn HD mặc định (
"44'/397'/0'/0'/1'"
)
near generate-key --useLedgerKey
You should then see the following prompt to confirm this request on your Ledger device:
Make sure to connect your Ledger and open NEAR app
Waiting for confirmation on Ledger...
After confirming the request on your Ledger device, a public key and implicit accountId will be displayed.
**Example Response:**
Using public key: ed25519:B22RP10g695wyeRvKIWv61NjmQZEkWTMzAYgdfx6oSeB2
Implicit account: 42c320xc20739fd9a6bqf2f89z61rd14efe5d3de234199bc771235a4bb8b0e1
3b) near generate-key --useLedgerKey="HD path you specify"
Sử dụng thiết bị Ledger đã được kết nối để hiển thị một pubic key và implicit account sử dụng đường dẫn HD mặc định.
near generate-key --useLedgerKey="44'/397'/0'/0'/2'"
You should then see the following prompt to confirm this request on your Ledger device:
Make sure to connect your Ledger and open NEAR app
Waiting for confirmation on Ledger...
After confirming the request on your Ledger device, a public key and implicit accountId will be displayed.
**Ví dụ response nhận được là:**
Using public key: ed25519:B22RP10g695wye3dfa32rDjmQZEkWTMzAYgCX6oSeB2
Implicit account: 42c320xc20739ASD9a6bqf2Dsaf289z61rd14efe5d3de23213789009afDsd5bb8b0e1
4a) near generate-key --seedPhrase="your seed phrase"
Sử dụng một seed phrase để hiển thị public key và implicit account
near generate-key --seedPhrase="cow moon right send now cool dense quark pretty see light after"
**Example Response:**
Key pair with ed25519:GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi public key for an account "e9fa50ac20522987a87e566fcd6febdc97bd35c8c489999ca8aff465c56969c3"
4b) near generate-key accountId --seedPhrase="your seed phrase"
Sử dụng một seed phrase để hiển thị public key mà không có implicit account.
near generate-key example.testnet --seedPhrase="cow moon right send now cool dense quark pretty see light after"
**Example Response:**
Key pair with ed25519:GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi public key for an account "example.testnet"
near add-key
Thêm một full access hoặc một function access key vào một account nhất định.
Note: You will use an existing full access key for the account you would like to add a new key to. (near login
)
1) thêm một full access
key
- các tham số:
accountId
publicKey
Example:
near add-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S
**Example Response:**
Adding full access key = Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S to example-acct.testnet.
Transaction Id EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg
2) thêm một function access
key
- các tham số:
accountId
publicKey
--contract-id
- các tuỳ chọn:
--method-names
--allowance
accountId
là account bạn đang thêm key vào
--contract-id
là contract mà bạn đang cho phép các method được gọi
--method-names
là tùy chọn và nếu bị bỏ qua, tất cả các method của--contract-id
có thể được gọi.
--allowance
là số Ⓝ của key chỉ được phép chi cho phí gas. Nếu bị bỏ qua thì key sẽ chỉ có thể gọi các view method.
Note: Each transaction made with this key will have gas fees deducted from the initial allowance and once it runs out a new key must be issued.
Example:
near add-key example-acct.testnet GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi --contract-id example-contract.testnet --method-names example_method --allowance 30000000000
**Example Response:**
Adding function call access key = GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi to example-acct.testnet.
Transaction Id H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2r
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2r
near delete-key
Xóa một key hiện có cho một account nhất định.
- các tham số:
accountId
publicKey
- các tuỳ chọn:
default
Note: You will need separate full access key for the account you would like to delete a key from. (near login
)
Example:
near delete-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S
Example Response:
Transaction Id 4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT
Accounts
near create-account
Tạo một account sử dụng một
--masterAccount
để thanh toán cho quá trình tạo account và bất kỳ số dư ban đầu nào.
- các tham số:
accountId
--masterAccount
- các tuỳ chọn:
--initialBalance
Chú ýCommand này sẽ chỉ cho phép việc tạo subaccounts của
--masterAccount
. Tuy nhiên, bạn có thể tạo một top-level account nếu độ dài của account ID lớn hơn 31 ký tự. Nó được sử dụng phổ biến nhất cho việc tạo implicit account.Nếu bạn đang có dự định tạo một top-level
.testnet
hay.near
account bạn có thể sử dụngnear-api-js
[ tại đây ].
Example:
near create-account 7e094afcfc4eda8a970f6648cdf0dbd6de --masterAccount example-acct.testnet
Subaccount example:
near create-account sub-acct.example-acct.testnet --masterAccount example-acct.testnet
Example using --initialBalance
:
near create-account sub-acct2.example-acct.testnet --masterAccount example-acct.testnet --initialBalance 10
**Example Response:**
Saving key to '/HOME_DIR/.near-credentials/default/sub-acct2.example-acct.testnet.json'
Account sub-acct2.example-acct.testnet for network "default" was created.
near state
Hiển thị chi tiết về state của account.
- các tham số:
accountId
- các tuỳ chọn:
default
Example:
near state example.testnet
Example Response:
{
"amount": "99999999303364037168535000",
"locked": "0",
"code_hash": "G1PCjeQbvbUsJ8piXNb7Yg6dn3mfivDQN7QkvsVuMt4e",
"storage_usage": 53528,
"storage_paid_at": 0,
"block_height": 21577354,
"block_hash": "AWu1mrT3eMJLjqyhNHvMKrrbahN6DqcNxXanB5UH1RjB",
"formattedAmount": "99.999999303364037168535"
}
near send
Chuyển NEAR token (Ⓝ) từ một account này tới một account khác.
- các tham số:
senderId
receiverId
amount
- các tuỳ chọn:
default
Note: You will need a full access key for the sending account. (near login
)
Example:
near send sender.testnet receiver.testnet 10
Example Response
Sending 10 NEAR to receiver.testnet from sender.testnet
Transaction Id BYTr6WNyaEy2ykAiQB9P5VvTyrJcFk6Yw95HPhXC6KfN
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/BYTr6WNyaEy2ykAiQB9P5VvTyrJcFk6Yw95HPhXC6KfN
near delete
Xóa một account và chuyển số dư còn lại vào account thụ hưởng.
note
The deleted account's name will be made available for use after this action is performed.
- các tham số:
accountId
beneficiaryId
- các tuỳ chọn:
default
Example:
near delete sub-acct2.example-acct.testnet example-acct.testnet
Example Response:
Deleting account. Account id: sub-acct2.example-acct.testnet, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, beneficiary: example-acct.testnet
Transaction Id 4x8xohER1E3yxeYdXPfG8GvXin1ShiaroqE5GdCd5YxX
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/4x8xohER1E3yxeYdXPfG8GvXin1ShiaroqE5GdCd5YxX
Account sub-acct2.example-acct.testnet for network "default" was deleted.
Contracts
near deploy
Deploy một smart contract trên một accountId nhất định.
- các tham số:
accountId
.wasmFile
- các tuỳ chọn:
initFunction
initArgs
initGas
initDeposit
Note: You will need a full access key for the account you are deploying the contract to. (near login
)
Example:
near deploy --accountId example-contract.testnet --wasmFile out/example.wasm
Initialize Example:
near deploy --accountId example-contract.testnet --wasmFile out/example.wasm --initFunction new --initArgs '{"owner_id": "example-contract.testnet", "total_supply": "10000000"}'
**Example Response:**
Starting deployment. Account id: example-contract.testnet, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: main.wasm
Transaction Id G8GhhPuujMHTRnwursPXE1Lv5iUZ8WUecwiST1PcKWMt
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/G8GhhPuujMHTRnwursPXE1Lv5iUZ8WUecwiST1PcKWMt
Done deploying to example-contract.testnet
near dev-deploy
Tạo một development account và deploy một smart contract cho account này. Không cần có access keys. (
testnet
only)
- các tham số:
.wasmFile
- các tuỳ chọn:
default
Example:
near dev-deploy out/main.wasm
Example Response:
Starting deployment. Account id: dev-1603749005325-6432576, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: out/main.wasm
Transaction Id 5nixQT87KeN3eZFX7zwBLUAKSY4nyjhwzLF27SWWKkAp
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/5nixQT87KeN3eZFX7zwBLUAKSY4nyjhwzLF27SWWKkAp
Done deploying to dev-1603749005325-6432576
near call
Thực hiện một contract call có thể sửa đổi hoặc xem state.
Note: Contract calls require a transaction fee (gas) so you will need an access key for the --accountId
that will be charged. (near login
)
- các tham số:
contractName
method_name
{ args }
--accountId
Các tuỳ chọn | Mô tả |
---|---|
--gas | Lượng gas tối đa mà call này có thể sử dụng (tính theo đơn vị gas) |
--deposit hoặc --amount | Số lượng token đính kèm (đơn vị NEAR) vào một function call |
--depositYocto | Số lượng token đính kèm (đơn vị yoctoNEAR) vào một function call |
--base64 | Coi các tham số là base64-encoded |
Tip: There are two ways to deal with methods that require empty { args }
. Either send {"field": null}
or simply omit this field and pass in nothing: {}
Ví dụ:
near call guest-book.testnet addMessage '{"text": "Aloha"}' --account-id example-acct.testnet
Ví dụ về response nhận được:
Scheduling a call: guest-book.testnet.addMessage({"text": "Aloha"})
Transaction Id FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK
''
near view
Tạo một contract call mà chỉ có thể view state. (miễn phí)
- các tham số:
contractName
method_name
{ args }
- các tuỳ chọn:
default
Ví dụ:
near view guest-book.testnet getMessages '{}'
Example Response:
View call: guest-book.testnet.getMessages({})
[
{ premium: false, sender: 'waverlymaven.testnet', text: 'TGIF' },
{
premium: true,
sender: 'waverlymaven.testnet',
text: 'Hello from New York 🌈'
},
{ premium: false, sender: 'fhr.testnet', text: 'Hi' },
{ premium: true, sender: 'eugenethedream', text: 'test' },
{ premium: false, sender: 'dongri.testnet', text: 'test' },
{ premium: false, sender: 'dongri.testnet', text: 'hello' },
{ premium: true, sender: 'dongri.testnet', text: 'hey' },
{ premium: false, sender: 'hirokihori.testnet', text: 'hello' },
{ premium: true, sender: 'eugenethedream', text: 'hello' },
{ premium: false, sender: 'example-acct.testnet', text: 'Aloha' },
[length]: 10
]
near view-state
Trả về state của contract (các cặp key / value) ở định dạng utf-8 hoặc định dạng borsh serialized.
Example:
near view-state dao.sputnik-v2.testnet --finality final
OR
near view-state dao.sputnik-v2.testnet --block-id 53199035
**Example Response:**
[
{
key: <Buffer 00>,
value: <Buffer 07 00 67 65 6e 73 69 0b 47 20 44 41 4f>
},
{
key: <Buffer 01>,
value: <Buffer 01 02 00 03 61 6c 0d 2a 3a 41 64 50 72 6f 70 73 07 63 75 6e 69 ... 222 more bytes>
},
{
key: <Buffer 03 00>,
value: <Buffer 00 14 6e 65 61 72 2d 78 6d 70 6c 2e 74 73 0f 41 64 20 4e 77 43 6f 75 63 69 02 18 ... 133 more bytes>
},
{
key: <Buffer 53 54 41 45>,
value: <Buffer 01 00 80 66 de c1 b9 a2 df e3 03 02 ... 39 more bytes>
}
]
Transactions
near tx-status
Displays transaction status details for given transaction hash and accountId.
- arguments:
tx hash
--accountId
ORaccountId:tx_hash
(see examples below) - options:
default
Example:
near tx-status near-example.testnet:6hnVD3n4LvQbUrWofSjxbN2uwLLANnkXLqRYPnMbsP3j
OR
near tx-status 6hnVD3n4LvQbUrWofSjxbN2uwLLANnkXLqRYPnMbsP3j --accountId near-example.testnet
**Example Response:**
Transaction near-example.testnet:6hnVD3n4LvQbUrWofSjxbN2uwLLANnkXLqRYPnMbsP3j
{
status: { SuccessValue: '' },
transaction: {
signer_id: 'near-example.testnet',
public_key: 'ed25519:3PTXqkrMLb1nVchxzC4RX5fUShq7EBqkSV7Te17n5J42',
nonce: 50891444000001,
receiver_id: 'receiver.testnet',
actions: [ { Transfer: { deposit: '1000000000000000000000000' } } ],
signature: 'ed25519:4oBvWrBYJT6YPRaJctWxtsMSMcKBcLhCvWAipoQ18qRe4myxJNnkR6hypw2Nqcc99Yg6e47yqmwt3VDXiyGHth7w',
hash: '6hnVD3n4LvQbUrWofSjxbN2uwLLANnkXLqRYPnMbsP3j'
},
transaction_outcome: {
proof: [],
block_hash: 'ASUCV9Zk5R9KbXB2ngMernS38KgFwK3Y8x8zZjSX8xcK',
id: '6hnVD3n4LvQbUrWofSjxbN2uwLLANnkXLqRYPnMbsP3j',
outcome: {
logs: [],
receipt_ids: [ 'JBXhsPNwx1g2gmrAXFy9UmP8ziSgsZn6kxDcijNsbABo' ],
gas_burnt: 223182562500,
tokens_burnt: '22318256250000000000',
executor_id: 'near-example.testnet',
status: {
SuccessReceiptId: 'JBXhsPNwx1g2gmrAXFy9UmP8ziSgsZn6kxDcijNsbABo'
}
}
},
receipts_outcome: [
{
proof: [],
block_hash: '5gsqDtub9x2L6jnThg6gi3FZTVzusvjqhxFWYQ31hedw',
id: 'JBXhsPNwx1g2gmrAXFy9UmP8ziSgsZn6kxDcijNsbABo',
outcome: {
logs: [],
receipt_ids: [ 'DxBEN5ZcfZJ21e2axAe7aLwTVSyxCmgDuht1TsDXT2DT' ],
gas_burnt: 223182562500,
tokens_burnt: '22318256250000000000',
executor_id: 'receiver.testnet',
status: { SuccessValue: '' }
}
},
{
proof: [],
block_hash: '9BcSFdzHzXtQhSS5uPUY6mAtNWwbQJoEiyqwZk4GAbe6',
id: 'DxBEN5ZcfZJ21e2axAe7aLwTVSyxCmgDuht1TsDXT2DT',
outcome: {
logs: [],
receipt_ids: [],
gas_burnt: 0,
tokens_burnt: '0',
executor_id: 'near-example.testnet',
status: { SuccessValue: '' }
}
}
]
}
Validators
near validators current
Displays details of current validators.
- amount staked
- number of seats
- percentage of uptime
- expected block production
- blocks actually produced
- arguments:
current
- options:
default
Example:
near validators current
Example for mainnet
:
NEAR_ENV=mainnet near validators current
**Example Response:**
Validators (total: 49, seat price: 1,976,588):
.--------------------------------------------------------------------------------------------------------------------.
| Validator Id | Stake | Seats | % Online | Blocks produced | Blocks expected |
|----------------------------------------------|------------|---------|----------|-----------------|-----------------|
| cryptium.poolv1.near | 13,945,727 | 7 | 100% | 1143 | 1143 |
| astro-stakers.poolv1.near | 11,660,189 | 5 | 100% | 817 | 817 |
| blockdaemon.poolv1.near | 11,542,867 | 5 | 76.74% | 627 | 817 |
| zavodil.poolv1.near | 11,183,187 | 5 | 100% | 818 | 818 |
| bisontrails.poolv1.near | 10,291,696 | 5 | 99.38% | 810 | 815 |
| dokiacapital.poolv1.near | 7,906,352 | 3 | 99.54% | 650 | 653 |
| chorusone.poolv1.near | 7,480,508 | 3 | 100% | 490 | 490 |
| figment.poolv1.near | 6,931,070 | 3 | 100% | 489 | 489 |
| stardust.poolv1.near | 6,401,678 | 3 | 100% | 491 | 491 |
| anonymous.poolv1.near | 6,291,821 | 3 | 97.55% | 479 | 491 |
| d1.poolv1.near | 6,265,109 | 3 | 100% | 491 | 491 |
| near8888.poolv1.near | 6,202,968 | 3 | 99.38% | 486 | 489 |
| rekt.poolv1.near | 5,950,212 | 3 | 100% | 490 | 490 |
| epic.poolv1.near | 5,639,256 | 2 | 100% | 326 | 326 |
| fresh.poolv1.near | 5,460,410 | 2 | 100% | 327 | 327 |
| buildlinks.poolv1.near | 4,838,398 | 2 | 99.38% | 325 | 327 |
| jubi.poolv1.near | 4,805,921 | 2 | 100% | 326 | 326 |
| openshards.poolv1.near | 4,644,553 | 2 | 100% | 326 | 326 |
| jazza.poolv1.near | 4,563,432 | 2 | 100% | 327 | 327 |
| northernlights.poolv1.near | 4,467,978 | 2 | 99.39% | 326 | 328 |
| inotel.poolv1.near | 4,427,152 | 2 | 100% | 327 | 327 |
| baziliknear.poolv1.near | 4,261,142 | 2 | 100% | 328 | 328 |
| stakesabai.poolv1.near | 4,242,618 | 2 | 100% | 326 | 326 |
| everstake.poolv1.near | 4,234,552 | 2 | 100% | 327 | 327 |
| stakin.poolv1.near | 4,071,704 | 2 | 100% | 327 | 327 |
| certusone.poolv1.near | 3,734,505 | 1 | 100% | 164 | 164 |
| lux.poolv1.near | 3,705,394 | 1 | 100% | 163 | 163 |
| staked.poolv1.near | 3,683,365 | 1 | 100% | 164 | 164 |
| lunanova.poolv1.near | 3,597,231 | 1 | 100% | 163 | 163 |
| appload.poolv1.near | 3,133,163 | 1 | 100% | 163 | 163 |
| smart-stake.poolv1.near | 3,095,711 | 1 | 100% | 164 | 164 |
| artemis.poolv1.near | 3,009,462 | 1 | 99.39% | 163 | 164 |
| moonlet.poolv1.near | 2,790,296 | 1 | 100% | 163 | 163 |
| nearfans.poolv1.near | 2,771,137 | 1 | 100% | 163 | 163 |
| nodeasy.poolv1.near | 2,692,745 | 1 | 99.39% | 163 | 164 |
| erm.poolv1.near | 2,653,524 | 1 | 100% | 164 | 164 |
| zkv_staketosupportprivacy.poolv1.near | 2,548,343 | 1 | 99.39% | 163 | 164 |
| dsrvlabs.poolv1.near | 2,542,925 | 1 | 100% | 164 | 164 |
| 08investinwomen_runbybisontrails.poolv1.near | 2,493,123 | 1 | 100% | 163 | 163 |
| electric.poolv1.near | 2,400,532 | 1 | 99.39% | 163 | 164 |
| sparkpool.poolv1.near | 2,378,191 | 1 | 100% | 163 | 163 |
| hashquark.poolv1.near | 2,376,424 | 1 | 100% | 164 | 164 |
| masternode24.poolv1.near | 2,355,634 | 1 | 100% | 164 | 164 |
| sharpdarts.poolv1.near | 2,332,398 | 1 | 99.38% | 162 | 163 |
| fish.poolv1.near | 2,315,249 | 1 | 100% | 163 | 163 |
| ashert.poolv1.near | 2,103,327 | 1 | 97.56% | 160 | 164 |
| 01node.poolv1.near | 2,058,200 | 1 | 100% | 163 | 163 |
| finoa.poolv1.near | 2,012,304 | 1 | 100% | 163 | 163 |
| majlovesreg.poolv1.near | 2,005,032 | 1 | 100% | 164 | 164 |
'--------------------------------------------------------------------------------------------------------------------'
near validators next
Displays details for the next round of validators.
- total number of seats available
- seat price
- amount staked
- number of seats assigned per validator
- arguments:
next
- options:
default
Example:
near validators next
Example for mainnet
:
NEAR_ENV=mainnet near validators next
**Example Response:**
Next validators (total: 49, seat price: 1,983,932):
.----------------------------------------------------------------------------------------------.
| Status | Validator | Stake | Seats |
|----------|----------------------------------------------|--------------------------|---------|
| Rewarded | cryptium.poolv1.near | 13,945,727 -> 14,048,816 | 7 |
| Rewarded | astro-stakers.poolv1.near | 11,660,189 -> 11,704,904 | 5 |
| Rewarded | blockdaemon.poolv1.near | 11,542,867 -> 11,545,942 | 5 |
| Rewarded | zavodil.poolv1.near | 11,183,187 -> 11,204,123 | 5 |
| Rewarded | bisontrails.poolv1.near | 10,291,696 -> 10,297,923 | 5 |
| Rewarded | dokiacapital.poolv1.near | 7,906,352 -> 8,097,275 | 4 |
| Rewarded | chorusone.poolv1.near | 7,480,508 -> 7,500,576 | 3 |
| Rewarded | figment.poolv1.near | 6,931,070 -> 6,932,916 | 3 |
| Rewarded | stardust.poolv1.near | 6,401,678 -> 6,449,363 | 3 |
| Rewarded | anonymous.poolv1.near | 6,291,821 -> 6,293,497 | 3 |
| Rewarded | d1.poolv1.near | 6,265,109 -> 6,266,777 | 3 |
| Rewarded | near8888.poolv1.near | 6,202,968 -> 6,204,620 | 3 |
| Rewarded | rekt.poolv1.near | 5,950,212 -> 5,951,797 | 2 |
| Rewarded | epic.poolv1.near | 5,639,256 -> 5,640,758 | 2 |
| Rewarded | fresh.poolv1.near | 5,460,410 -> 5,461,811 | 2 |
| Rewarded | buildlinks.poolv1.near | 4,838,398 -> 4,839,686 | 2 |
| Rewarded | jubi.poolv1.near | 4,805,921 -> 4,807,201 | 2 |
| Rewarded | openshards.poolv1.near | 4,644,553 -> 4,776,692 | 2 |
| Rewarded | jazza.poolv1.near | 4,563,432 -> 4,564,648 | 2 |
| Rewarded | northernlights.poolv1.near | 4,467,978 -> 4,469,168 | 2 |
| Rewarded | inotel.poolv1.near | 4,427,152 -> 4,428,331 | 2 |
| Rewarded | baziliknear.poolv1.near | 4,261,142 -> 4,290,338 | 2 |
| Rewarded | stakesabai.poolv1.near | 4,242,618 -> 4,243,748 | 2 |
| Rewarded | everstake.poolv1.near | 4,234,552 -> 4,235,679 | 2 |
| Rewarded | stakin.poolv1.near | 4,071,704 -> 4,072,773 | 2 |
| Rewarded | certusone.poolv1.near | 3,734,505 -> 3,735,500 | 1 |
| Rewarded | lux.poolv1.near | 3,705,394 -> 3,716,381 | 1 |
| Rewarded | staked.poolv1.near | 3,683,365 -> 3,684,346 | 1 |
| Rewarded | lunanova.poolv1.near | 3,597,231 -> 3,597,836 | 1 |
| Rewarded | appload.poolv1.near | 3,133,163 -> 3,152,302 | 1 |
| Rewarded | smart-stake.poolv1.near | 3,095,711 -> 3,096,509 | 1 |
| Rewarded | artemis.poolv1.near | 3,009,462 -> 3,010,265 | 1 |
| Rewarded | moonlet.poolv1.near | 2,790,296 -> 2,948,565 | 1 |
| Rewarded | nearfans.poolv1.near | 2,771,137 -> 2,771,875 | 1 |
| Rewarded | nodeasy.poolv1.near | 2,692,745 -> 2,693,463 | 1 |
| Rewarded | erm.poolv1.near | 2,653,524 -> 2,654,231 | 1 |
| Rewarded | dsrvlabs.poolv1.near | 2,542,925 -> 2,571,865 | 1 |
| Rewarded | zkv_staketosupportprivacy.poolv1.near | 2,548,343 -> 2,549,022 | 1 |
| Rewarded | 08investinwomen_runbybisontrails.poolv1.near | 2,493,123 -> 2,493,787 | 1 |
| Rewarded | masternode24.poolv1.near | 2,355,634 -> 2,456,226 | 1 |
| Rewarded | fish.poolv1.near | 2,315,249 -> 2,415,831 | 1 |
| Rewarded | electric.poolv1.near | 2,400,532 -> 2,401,172 | 1 |
| Rewarded | sparkpool.poolv1.near | 2,378,191 -> 2,378,824 | 1 |
| Rewarded | hashquark.poolv1.near | 2,376,424 -> 2,377,057 | 1 |
| Rewarded | sharpdarts.poolv1.near | 2,332,398 -> 2,332,948 | 1 |
| Rewarded | ashert.poolv1.near | 2,103,327 -> 2,103,887 | 1 |
| Rewarded | 01node.poolv1.near | 2,058,200 -> 2,058,760 | 1 |
| Rewarded | finoa.poolv1.near | 2,012,304 -> 2,015,808 | 1 |
| Rewarded | majlovesreg.poolv1.near | 2,005,032 -> 2,005,566 | 1 |
'----------------------------------------------------------------------------------------------'
near proposals
Displays validator proposals for epoch after next.
- expected seat price
- status of proposals
- previous amount staked and new amount that will be staked
- amount of seats assigned per validator
- arguments:
none
- options:
default
Example:
near proposals
Example for mainnet
:
NEAR_ENV=mainnet near proposals
**Example Response:**
Proposals for the epoch after next (new: 51, passing: 49, expected seat price = 1,983,932)
.--------------------------------------------------------------------------------------------------------.
| Status | Validator | Stake => New Stake | Seats |
|--------------------|----------------------------------------------|--------------------------|---------|
| Proposal(Accepted) | cryptium.poolv1.near | 13,945,727 => 14,041,766 | 7 |
| Proposal(Accepted) | astro-stakers.poolv1.near | 11,660,189 => 11,705,673 | 5 |
| Proposal(Accepted) | blockdaemon.poolv1.near | 11,542,867 => 11,545,942 | 5 |
| Proposal(Accepted) | zavodil.poolv1.near | 11,183,187 => 11,207,805 | 5 |
| Proposal(Accepted) | bisontrails.poolv1.near | 10,291,696 => 10,300,978 | 5 |
| Proposal(Accepted) | dokiacapital.poolv1.near | 7,906,352 => 8,097,275 | 4 |
| Proposal(Accepted) | chorusone.poolv1.near | 7,480,508 => 7,568,268 | 3 |
| Proposal(Accepted) | figment.poolv1.near | 6,931,070 => 6,932,916 | 3 |
| Proposal(Accepted) | stardust.poolv1.near | 6,401,678 => 6,449,363 | 3 |
| Proposal(Accepted) | anonymous.poolv1.near | 6,291,821 => 6,293,497 | 3 |
| Proposal(Accepted) | d1.poolv1.near | 6,265,109 => 6,266,777 | 3 |
| Proposal(Accepted) | near8888.poolv1.near | 6,202,968 => 6,204,620 | 3 |
| Proposal(Accepted) | rekt.poolv1.near | 5,950,212 => 5,951,797 | 2 |
| Proposal(Accepted) | epic.poolv1.near | 5,639,256 => 5,640,758 | 2 |
| Proposal(Accepted) | fresh.poolv1.near | 5,460,410 => 5,461,811 | 2 |
| Proposal(Accepted) | buildlinks.poolv1.near | 4,838,398 => 4,839,686 | 2 |
| Proposal(Accepted) | jubi.poolv1.near | 4,805,921 => 4,807,201 | 2 |
| Proposal(Accepted) | openshards.poolv1.near | 4,644,553 => 4,776,692 | 2 |
| Proposal(Accepted) | jazza.poolv1.near | 4,563,432 => 4,564,648 | 2 |
| Proposal(Accepted) | northernlights.poolv1.near | 4,467,978 => 4,469,168 | 2 |
| Proposal(Accepted) | inotel.poolv1.near | 4,427,152 => 4,428,331 | 2 |
| Proposal(Accepted) | baziliknear.poolv1.near | 4,261,142 => 4,290,891 | 2 |
| Proposal(Accepted) | stakesabai.poolv1.near | 4,242,618 => 4,243,748 | 2 |
| Proposal(Accepted) | everstake.poolv1.near | 4,234,552 => 4,235,679 | 2 |
| Proposal(Accepted) | stakin.poolv1.near | 4,071,704 => 4,072,773 | 2 |
| Proposal(Accepted) | certusone.poolv1.near | 3,734,505 => 3,735,500 | 1 |
| Proposal(Accepted) | lux.poolv1.near | 3,705,394 => 3,716,381 | 1 |
| Proposal(Accepted) | staked.poolv1.near | 3,683,365 => 3,684,346 | 1 |
| Proposal(Accepted) | lunanova.poolv1.near | 3,597,231 => 3,597,836 | 1 |
| Proposal(Accepted) | appload.poolv1.near | 3,133,163 => 3,152,302 | 1 |
| Proposal(Accepted) | smart-stake.poolv1.near | 3,095,711 => 3,096,509 | 1 |
| Proposal(Accepted) | artemis.poolv1.near | 3,009,462 => 3,010,265 | 1 |
| Proposal(Accepted) | moonlet.poolv1.near | 2,790,296 => 2,948,565 | 1 |
| Proposal(Accepted) | nearfans.poolv1.near | 2,771,137 => 2,771,875 | 1 |
| Proposal(Accepted) | nodeasy.poolv1.near | 2,692,745 => 2,693,463 | 1 |
| Proposal(Accepted) | erm.poolv1.near | 2,653,524 => 2,654,231 | 1 |
| Proposal(Accepted) | dsrvlabs.poolv1.near | 2,542,925 => 2,571,865 | 1 |
| Proposal(Accepted) | zkv_staketosupportprivacy.poolv1.near | 2,548,343 => 2,549,022 | 1 |
| Proposal(Accepted) | 08investinwomen_runbybisontrails.poolv1.near | 2,493,123 => 2,493,787 | 1 |
| Proposal(Accepted) | masternode24.poolv1.near | 2,355,634 => 2,456,226 | 1 |
| Proposal(Accepted) | fish.poolv1.near | 2,315,249 => 2,415,831 | 1 |
| Proposal(Accepted) | electric.poolv1.near | 2,400,532 => 2,401,172 | 1 |
| Proposal(Accepted) | sparkpool.poolv1.near | 2,378,191 => 2,378,824 | 1 |
| Proposal(Accepted) | hashquark.poolv1.near | 2,376,424 => 2,377,057 | 1 |
| Proposal(Accepted) | sharpdarts.poolv1.near | 2,332,398 => 2,332,948 | 1 |
| Proposal(Accepted) | ashert.poolv1.near | 2,103,327 => 2,103,887 | 1 |
| Proposal(Accepted) | 01node.poolv1.near | 2,058,200 => 2,059,314 | 1 |
| Proposal(Accepted) | finoa.poolv1.near | 2,012,304 => 2,015,808 | 1 |
| Proposal(Accepted) | majlovesreg.poolv1.near | 2,005,032 => 2,005,566 | 1 |
| Proposal(Declined) | huobipool.poolv1.near | 1,666,976 | 0 |
| Proposal(Declined) | hb436_pool.poolv1.near | 500,030 | 0 |
'--------------------------------------------------------------------------------------------------------'
REPL
near repl
Launches NEAR REPL (an interactive JavaScript programming environment) connected to NEAR.
- arguments:
none
- options:
--accountId
To launch, run:
near repl
- You will then be shown a prompt
>
and can begin interacting with NEAR. - Try typing the following into your prompt that converts NEAR (Ⓝ) into yoctoNEAR (10^-24):
nearAPI.utils.format.parseNearAmount('1000')
You can also use an
--accountId
withnear repl
.
Example:
near repl --accountId example-acct.testnet
- Then try console logging
account
after the>
prompt.
console.log(account)
Example Response:
Account {
accessKeyByPublicKeyCache: {},
connection: Connection {
networkId: 'default',
provider: JsonRpcProvider { connection: [Object] },
signer: InMemorySigner { keyStore: [MergeKeyStore] }
},
accountId: 'example-acct.testnet',
_ready: Promise { undefined },
_state: {
amount: '98786165075093615800000000',
locked: '0',
code_hash: '11111111111111111111111111111111',
storage_usage: 741,
storage_paid_at: 0,
block_height: 21661252,
block_hash: 'HbAj25dTzP3ssYjNRHov9BQ72UxpHGVqZK1mZwGdGNbo'
}
}
You can also get a private key's public key.
- First, declare a
privateKey
variable:
const myPrivateKey =
"3fKM9Rr7LHyzhhzmmedXLvc59rayfh1oUYS3VfUcxwpAFQZtdx1G9aTY6i8hG9mQtYoycTEFTBtatgNKHRtYamrS";
- Then, run:
nearAPI.KeyPair.fromString(myPrivateKey).publicKey.toString();
With NEAR REPL, you have complete access to near-api-js
to help you develop on the NEAR platform.
Options
Option | Description |
---|---|
--help | shows help (can be used alone or on any command) |
--version | shows installed version of near-cli |
--nodeUrl , --node_url | selects an RPC URL (testnet , mainnet , betanet ) |
--helperUrl | points to a contract helper instance you want to use for account creation / management |
--keyPath | specify a path to --masterAccount key |
--accountId , --account_id | selects an account ID |
--useLedgerKey | uses Ledger with given HD key path [default: "44'/397'/0'/0'/1'"] |
--seedPhrase | uses a mnemonic seed phrase |
--seedPath | specify a HD path derivation [default: "m/44'/397'/0'"] |
--walletUrl | selects a NEAR wallet URL |
--contractName | selects an account contract name |
--masterAccount | selects a master account |
--helperAccount | selects an expected top-level account for a network |
--verbose , -v | shows verbose output |
--gas | specifies amount of gas to use for a contract call [default: "100000000000000"] |
--deposit | Number of NEAR tokens (Ⓝ) to attach [default: "0"] |
--depositYocto | Number of tokens to attach (in yocto Ⓝ) to a function call [default: null] |
Got a question?
>Ask it on StackOverflow!