Account
Main class for account operations.
```typescript
const account = new Account(accountId, provider, privateKey)
// Get state
const state = await account.getState() // { balance: { total, available, locked }, storageUsage }
// Transfer NEAR
await account.transfer({ receiverId: "bob.testnet", amount: NEAR.toUnits("1"), token: NEAR })
// Call contract
await account.callFunction({
contractId: "contract.testnet",
methodName: "set_greeting",
args: { message: "Hello" },
deposit: 0n,
gas: 30_000_000_000_000n
})
// Sign and send transaction
await account.signAndSendTransaction({
receiverId: "contract.testnet",
actions: [
actions.functionCall("method", { arg: "value" }, 30_000_000_000_000n, 0n),
actions.transfer(1_000_000_000_000_000_000_000_000n)
]
})
```
Provider
RPC client for querying blockchain.
```typescript
const provider = new JsonRpcProvider({ url: "https://rpc.mainnet.near.org" })
// Failover provider
const failover = new FailoverRpcProvider([
new JsonRpcProvider({ url: "https://rpc.mainnet.near.org" }),
new JsonRpcProvider({ url: "https://rpc.mainnet.pagoda.co" })
])
// Query methods
await provider.viewAccount({ accountId: "alice.near" })
await provider.viewAccessKey({ accountId, publicKey })
await provider.callFunction({ contractId, method: "get_greeting", args: {} })
await provider.viewBlock({ finality: "final" })
await provider.sendTransaction(signedTx)
```
Crypto
Key management and cryptographic operations.
```typescript
import { KeyPair, PublicKey } from "near-api-js"
// Generate random keypair
const keyPair = KeyPair.fromRandom("ed25519")
// From string
const keyPair = KeyPair.fromString("ed25519:5Fg2...")
// Sign and verify
const { signature, publicKey } = keyPair.sign(data)
const verified = keyPair.verify(message, signature)
```
Tokens
FT and NFT support.
```typescript
import { NEAR, FungibleToken } from "near-api-js/tokens"
import { USDC } from "near-api-js/tokens/mainnet"
// Unit conversion
NEAR.toUnits("1.5") // 1500000000000000000000000n
NEAR.toDecimal(amount) // "1.5"
// Transfer FT
await account.transfer({ receiverId: "bob.near", amount: USDC.toUnits("50"), token: USDC })
// Custom FT
const token = new FungibleToken("usdt.tether-token.near", { decimals: 6, name: "USDT", symbol: "USDT" })
```
Actions
All transaction actions.
```typescript
import { actions } from "near-api-js"
actions.transfer(amount)
actions.functionCall(methodName, args, gas, deposit)
actions.createAccount()
actions.deployContract(wasmBytes)
actions.addFullAccessKey(publicKey)
actions.addFunctionAccessKey(publicKey, contractId, methodNames, allowance)
actions.deleteKey(publicKey)
actions.deleteAccount(beneficiaryId)
actions.stake(amount, publicKey)
actions.signedDelegate(signedDelegateAction) // Meta transactions
```