Data Structures
This reference details the shape of objects returned by the Near client. Use this to understand exactly what fields are available when parsing results.
Transaction Result (FinalExecutionOutcome)
Returned by .send() and near.call().
type FinalExecutionOutcome = {
// High-level status of the transaction execution
final_execution_status: "NONE" | "INCLUDED" | "EXECUTED_OPTIMISTIC" | "FINAL";
// Detailed status of the transaction
status:
| { SuccessValue: string } // Base64 encoded return value
| { SuccessReceiptId: string } // ID of the final receipt
| { Failure: object }; // Error object if failed
// The transaction itself
transaction: {
signer_id: string;
public_key: string;
nonce: number;
receiver_id: string;
actions: Action[];
signature: string;
hash: string;
};
// Execution outcome of the transaction (initial receipt)
transaction_outcome: ExecutionOutcomeWithId;
// Execution outcomes of all subsequent receipts (cross-contract calls)
receipts_outcome: ExecutionOutcomeWithId[];
};
Execution Outcome (ExecutionOutcomeWithId)
Contains gas usage and logs.
type ExecutionOutcomeWithId = {
id: string; // Receipt ID
block_hash: string;
outcome: {
logs: string[]; // Console logs from the contract
receipt_ids: string[]; // IDs of receipts generated by this execution
gas_burnt: number; // Gas used in Tgas units * 1e12
tokens_burnt: string; // NEAR burnt (yoctoNEAR)
executor_id: string; // The account that executed this receipt
status: ExecutionStatus;
};
};
Account Details (AccountView)
Returned by near.getAccountDetails(accountId).
type AccountView = {
amount: string; // Balance in yoctoNEAR
locked: string; // Staked balance in yoctoNEAR
code_hash: string; // Hash of the contract code (111111... if none)
storage_usage: number; // Storage used in bytes
storage_paid_at: number;
block_height: number;
block_hash: string;
};
Access Key (AccessKeyView)
Returned by near.getAccessKey(accountId, publicKey).
type AccessKeyView = {
nonce: number;
permission:
| "FullAccess"
| {
FunctionCall: {
receiver_id: string;
method_names: string[];
allowance: string | null;
};
};
};
Errors
FunctionCallError
Thrown when a smart contract panics.
class FunctionCallError extends NearError {
code: "FUNCTION_CALL_ERROR";
contractId: string; // The contract that failed
methodName?: string; // The method that failed
panic?: string; // The panic message (e.g. "ERR_NO_DEPOSIT")
logs: string[]; // Logs leading up to the failure
}
InvalidTransactionError
Thrown when the network rejects a transaction.
class InvalidTransactionError extends NearError {
code: "INVALID_TRANSACTION";
retryable: boolean; // True if it was a transient network issue
shardCongested: boolean;
shardStuck: boolean;
}
Utility Functions
Deterministic Account IDs (NEP-616)
deriveAccountId(stateInit)
Computes the deterministic account ID from initialization state.
import { deriveAccountId } from "near-kit";
deriveAccountId({
code: { accountId: "publisher.near" },
data: new Map([["owner", "alice.near"]]),
});
// => "0s1234567890abcdef1234567890abcdef12345678"
isDeterministicAccountId(accountId)
Checks if an account ID is deterministic (starts with 0s).
isDeterministicAccountId("0s123..."); // true
isDeterministicAccountId("alice.near"); // false
verifyDeterministicAccountId(accountId, stateInit)
Verifies an account ID matches the expected derivation.
verifyDeterministicAccountId("0s123...", {
code: { accountId: "publisher.near" },
data: new Map([["owner", "alice.near"]]),
});
// => true if matches
See Global Contracts.