Skip to main content
To change state on the blockchain (send money, write to a contract), you must send a transaction. Transactions cost Gas and must be signed by an account with a private key.

1. The Transaction Builder

The primary way to write data is the fluent Transaction Builder. It allows you to chain multiple actions into a single, atomic package.

2. Atomicity (Batching Actions)

You can chain multiple actions in one transaction. This is atomic: either every action succeeds, or the entire transaction is rolled back. This is perfect for scenarios like “Create an account AND fund it AND deploy a contract.”
If the init call fails, the account bob.alice.near will not be created, and the 1 NEAR will stay with Alice.

3. Attaching Gas & Deposits

When calling a function, you often need to attach Gas (computation limit) or a Deposit (real NEAR tokens). These are passed as the 4th argument (the options object) to .functionCall.
  • Gas: Defaults to 30 Tgas. Increase this for complex calculations.
  • Deposit: Defaults to 0. Required if the contract needs to pay for storage or if you are transferring value to a contract.

4. Working with Amounts (Dynamic Values)

For dynamic calculations, use the Amount helper instead of manually constructing strings:
Constants:
  • Amount.ZERO"0 yocto"
  • Amount.ONE_NEAR"1 NEAR"
  • Amount.ONE_YOCTO"1 yocto"

5. Shortcuts

For simple, single-action transactions, near-kit provides shortcuts. These are just syntax sugar around the builder.

6. Inspecting the Result

The .send() method returns a FinalExecutionOutcome object. This contains everything that happened on-chain.

7. Execution Speed (WaitUntil)

By default, .send() waits until the transaction is “Optimistically Executed” (usually 1-2 seconds). You can change this behavior.