starknet.js Documentation

website·Indexed 29 days ago

https://starknet-js.com

JavaScript and TypeScript library for interacting with the Starknet network. The documentation provides API references for versions 7.6.4, 10.8.0, and 11.x, including guides on connecting to smart contracts, handling Cairo data types, managing L1 to L2 communication, and implementing WalletAccount architecture for transaction signing.

Tokens
1.1M
Snippets
8.7K
Records
11.3K
Agent score
59%

What's inside starknet.js

  1. Overview of Starknet.js

    Starknet.js is the official JavaScript/TypeScript library for interacting with the Starknet network. It provides a comprehensive suite of tools for building decentralized applications (dApps), offering full TypeScript support, smart contract type generation, and optimized performance for Starknet's high throughput.
  2. Overview of RPC.RPCSPEC09 Namespace

    The RPC.RPCSPEC09 namespace provides the primary interface for interacting with Starknet RPC services. It organizes the API into three main sub-namespaces: API, WALLET_API, and PAYMASTER_API. It also re-exports essential types and method definitions used across these interfaces.
  3. Overview of CairoBytes31

    The CairoBytes31 class represents a Cairo core::bytes_31::bytes31 type. It stores up to 31 bytes, right-aligned in a fixed 31-byte buffer. Because it is right-aligned, the original length of the input is not recoverable from the value (e.g., '0x41' and '0x0041' result in the same CairoBytes31 value). For cases where the exact byte count must be preserved, use CairoByteArray instead. An empty string '' or '0x' is treated as empty bytes.
  4. Overview of Starknet Paymasters

    A Paymaster allows Starknet accounts to pay gas fees using alternative tokens (e.g., ETH, USDC) instead of STRK. There are two primary transaction types:

    • default: The account pays the fees using a supported token.
    • sponsored: A dApp covers the gas fees on behalf of the user.

    Requirement: Accounts must be compatible with SNIP-9 (Outside execution) to use Paymaster services.

  5. Overview of CairoArray

    The CairoArray class represents a Cairo dynamic array, which consists of any number of values of the same type. It supports both core::array::Array::<T> and core::array::Span::<T> ABI types. Unlike tuples, dynamic arrays carry their length on the wire; the serialized felts begin with the number of elements that follow. For felt252 or bytes31 element types, text input is automatically split into 31-character chunks.
  6. Overview of AccountInterface

    The AccountInterface is the primary interface for interacting with Starknet account contracts. It abstracts the complexities of nonce management, transaction signing using the account's private key, and interaction with the account contract's execute entrypoint. Key capabilities include transaction execution, fee estimation, contract deployment via the Universal Deployer Contract (UDC), paymaster support for sponsored transactions, and EIP-712 message signing.
  7. Overview of Outside Execution (Meta-Transactions)

    Outside Execution, based on SNIP-9, allows a protocol or third party to submit transactions on behalf of a user account provided they have the required signatures. This is primarily used for:

    1. Delayed Orders: Atomic control over execution (e.g., limit orders).
    2. Fee Subsidy: The executor (sender) pays the gas fees, enabling accounts without gas tokens to execute transactions.
  8. Overview of CairoTypeCustomEnum

    A CairoTypeCustomEnum represents a Cairo custom enum: one of several named variants, each carrying its own type. On the wire, it is represented as the index of the active variant followed by that variant's value. Because the value itself does not indicate which variant is active, the index must be provided unless a CairoCustomEnum object (which explicitly names its variant) is used.
  9. Overview of Outside Execution (Meta-Transactions)

    Outside Execution, based on SNIP-9, allows a protocol to submit transactions on behalf of a user account provided they have the necessary signatures. This is primarily used for:

    1. Delayed Orders: Providing atomic control over execution (e.g., matching limit orders).
    2. Fee Subsidy: Allowing the transaction sender (executor) to pay gas fees, enabling accounts without gas tokens to execute transactions.
  10. Overview of WalletAccount for DApps

    The WalletAccount class allows DApps to ask a browser wallet to sign and send transactions. Unlike the standard Account class, the private key is held securely within the wallet, meaning the DApp does not need to manage private key security.

    Constraint: This class is designed exclusively for DApps and cannot be used in Node.js scripts.

    To initialize a WalletAccount, a provider is required (either ProviderOptions like { nodeUrl } or a ProviderInterface instance such as RpcProvider) to handle all blockchain read activities.

  11. Overview of types.RPC.RPCSPEC08.API namespace

    The types.RPC.RPCSPEC08.API namespace provides the core type definitions for interacting with Starknet RPC and WebSocket interfaces. It includes a wide array of error interfaces used to handle specific failure cases during blockchain interactions, as well as type aliases for different categories of RPC methods.