Skip to main content
If you are coming from near-api-js, you will find near-kit to be more concise and less prone to “unit arithmetic” errors.

Core Philosophy Shifts

No Account Object

Use the central Near instance and pass signer IDs as arguments

Strings, not BigInts

No more utils.format or counting zeros

Fluent Builder

Chain readable methods instead of config objects

Side-by-Side Comparisons

1. Connecting & Keys

You have to manually assemble the Account, JsonRpcProvider, and KeyPairSigner.
import { Account } from "@near-js/accounts"
import { JsonRpcProvider } from "@near-js/providers"
import { KeyPairSigner } from "@near-js/signers"

const provider = new JsonRpcProvider({
  url: "https://test.rpc.fastnear.com",
})
const signer = KeyPairSigner.fromSecretKey("ed25519:...")
const account = new Account("alice.testnet", provider, signer)

2. Handling Units

Requires manual conversion, often leading to BN (BigNumber) headaches.
import { parseNearAmount } from "@near-js/utils"

const amount = parseNearAmount("10.5") // "1050000..."
const gas = "30000000000000" // Hope you counted the zeros right!

3. Calling Contracts

Arguments are passed inside a configuration object.
const account = new Account("alice.testnet", provider, signer)

await account.callFunction({
  contractId: "market.near",
  methodName: "buy",
  args: { id: "1" },
  gas: "50000000000000",
  deposit: parseNearAmount("1")!,
})

4. Error Handling

Often throws raw RPC errors or generic “TypedErrors” that are hard to parse.
try {
  // ...
} catch (e) {
  // You have to inspect e.type or e.message string matching
  if (e.type === 'FunctionCallError') { ... }
}

5. Access Keys

await account.addFunctionCallAccessKey({
  publicKey,
  contractId: "market.near",
  methodNames: ["buy"],
  allowance: parseNearAmount("0.25")!,
})