Skip to main content
Let’s get you connected to the NEAR Testnet and sending your first transaction in under 2 minutes.

Prerequisites

Node.js or Bun

Any recent version works

Testnet Account

Create one for free

Private Key

Starts with ed25519:...

Installation

npm install near-kit

Your First Script

1

Create a file named index.ts

import { Near } from "near-kit"

async function main() {
  // 1. Initialize the client
  // In a real app, ALWAYS use environment variables for keys!
  const near = new Near({
    network: "testnet",
    privateKey: "ed25519:...", // Replace with your actual private key
    defaultSignerId: "your-account.testnet", // Replace with your account ID
  })

  console.log("🔗 Connected to Testnet")

  // 2. Read some data (Free!)
  // Let's check the balance of the account we just connected
  const balance = await near.getBalance("your-account.testnet")
  console.log(`💰 Balance: ${balance}`)

  // 3. Write some data (Send a transaction)
  // We will send 1 NEAR to ourselves.
  // Note: "1 NEAR" is a string. No math required.
  console.log("💸 Sending 1 NEAR...")

  const result = await near
    .transaction("your-account.testnet")
    .transfer("your-account.testnet", "1 NEAR")
    .send()

  console.log(`✅ Transaction successful!`)
  console.log(`   Hash: ${result.transaction.hash}`)
}

main().catch(console.error)
2

Run it

bun run index.ts
3

See the result

You should see output like:
🔗 Connected to Testnet
💰 Balance: 10.5 NEAR
💸 Sending 1 NEAR...
✅ Transaction successful!
   Hash: 9abc123...

What’s Next?