near-kit’s superpowers is that it abstracts the “Signer.”
Whether a transaction is signed by a generic private key, a secure server-side keystore, or a user’s browser wallet, the code to build and send that transaction is identical.
This allows you to write “Universal Business Logic”—functions that define what to do, without caring where they are running.
1. The Business Logic
First, write your logic as a standalone function. It should accept aNear instance and a signerId.
2. Injecting the Near Instance
Now, let’s see how to initialize the Near object for different environments.
- Script
- Backend
- Frontend
- Testing
For simple scripts, passing a raw private key is the easiest method.
Summary
| Environment | Config Option | Who Signs? |
|---|---|---|
| Script | privateKey: "..." | The provided key string. |
| Backend | keyStore: store | The key matching signerId found in the store. |
| Frontend | wallet: adapter | The user (via wallet popup). |
| Sandbox | network: sandbox | The root account key (in-memory). |
buyItem) never needs to know which one is happening.