Learn to use APIs in JavaScript, Rust, and Python to interact with the blockchain.
We offer a collection of language-specific libraries that allow developers to interact with the NEAR blockchain from both frontend and backend applications. The different APIs allow you to perform a variety of actions on the NEAR blockchain, including but not limited to:
Create and manage NEAR accounts
Call functions on smart contracts
Transfer tokens, including native NEAR, Fungible Tokens, Non-Fungible Tokens
Sign transactions/meta-transactions/messages and broadcasting them to the network
To create a named account like user.testnet, you need to call the create_account function on near (or testnet), passing as parameters the new account ID, and a public key to add as FullAccess key.
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
🐍 py-near
Creating an account from a seed phrase
You can also create an account via a randomly generated seed phrase.
Accounts on NEAR can create sub-accounts under their own namespace, which is useful for organizing accounts by purpose — for example, project.user.testnet.
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
🐍 py-near
Create a sub-account and fund it with your main account:
Accounts on NEAR can delete themselves, transferring any remaining balance to a specified beneficiary account.
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
Deleting an account DOES NOT affect its sub-accounts - they will remain active.
The Beneficiary Only Receives NEAR TokensFungible (FTs) or Non-Fungible tokens (NFTs) held by the account ARE NOT automatically transferred. These tokens are still associated with the account, even after the account is deleted. Make sure to transfer those assets manually before deletion, or you’re risking losing them permanently. Once the account is gone, those assets are effectively stuck unless the same account is recreated by anyone (not necessarily you).
Make Sure the Beneficiary Account ExistsIf the beneficiary account doesn’t exist, all NEAR tokens sent to it will be burned. Double-check the account ID before proceeding.
A smart contract exposes its methods, and making a function call that modifies state requires a Signer/KeyPair. You can optionally attach a NEAR deposit to the call.
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
🐍 py-near
function call
typed contract
When using Typescript, you can type the return of callFunction<T>.
function call
typed contract
When using Typescript, you can type the return of Near.view<T> and Near.call<T>.
The only way to have true simultaneous transactions is to use multiple access keys on a same account. Each access key maintains its own nonce, allowing transactions signed with different keys to be processed in parallel:
Simultaneous execution means there’s no guarantee of order or success. Any transaction may fail independently. If your use case requires strict ordering, then you should stick to sending transactions sequentially from a single key.
Global contracts allow smart contracts to be deployed once and reused by any account without incurring high storage costs.There are two ways to reference a global contract:
By account: The contract code is tied to another account.
By hash: You reference the contract by its immutable code hash.
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
by account
by hash
by account
by hash
Once you’ve created an Account instance, you can deploy your regular contract as a global contract.
by account
by hash
To deploy a global contract by account, use the deploy_global_contract_code function with the as_account_id method.
View functions are read-only methods on a smart contract that do not modify state. You can call them without using an account or signing a transaction.
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
🐍 py-near
When using Typescript, you can type the return of callFunction<T>.
When using Typescript, you can type the return of Near.view<T>.
Copy
view_call_result = await account.view_function("guestbook.near-examples.testnet", "total_messages", {})# If args are required, they can be passed in like this in the 3rd argument:# {# "from_index": "0",# "limit": "10"# }print(view_call_result)
A Full Access key grants complete control over the account.Anyone with this key can transfer funds, sign transactions, interact with contracts, or even delete the account entirely.
Capping the amount of NEAR the key can spend on transaction fees
🌐 near-api-js
🌐 near-kit
🦀 near-api-rs
🐍 py-near
Copy
await account.add_public_key( "5X9WvUbRV3aSd9Py1LK7HAndqoktZtcgYdRjMt86SxMj", "example-contract.testnet", # Contract this key is allowed to call ["example_method"], # Methods this key is allowed to call (optional) 0.25 * NEAR # Gas allowance key can use to call methods (optional))
For security reasons, Function Call access keys can only be used with function calls that attach zero NEAR tokens. Any attempt to include a deposit will result in a failed transaction.
Users can sign messages using the wallet-selectorsignMessage method, which returns a signature. This signature can be verified using the following code: