NIL Foundation Documentation

website·Indexed 34 days ago

https://docs.nil.foundation/

Documentation for NIL, featuring technical specifications on finality, sequencing, and data availability, as well as developer tools including a Hardhat plugin, block explorer, NIL CLI, and a Solidity library with pre-compiled contracts and function modifiers. Includes a comprehensive client reference for @nilfoundation/niljs with type aliases for message parameters and wallet configurations.

Tokens
40K
Snippets
252
Records
367
Agent score
62%

What's inside NIL

  1. Implement Proposer-Builder Separation (PBS) for =nil; sequencing

    =nil; adopts the Proposer-Builder Separation (PBS) model to manage sequencing. This model creates a network of builders and searchers who compete for Maximum Extractable Value (MEV) through relay auctions. This architecture is designed to be fully compatible with Ethereum, allowing L1 builders and searchers to participate in =nil; to enhance protocol stability and liveness.
  2. Retrieve block information using PublicClient.getBlockByHash

    The getBlockByHash method retrieves information about a block using its hash. It allows specifying whether to return full transaction information and requires the shardId where the block was generated.
    import { PublicClient, HttpTransport } from '@nilfoundation/niljs';
    
    const client = new PublicClient({
      transport: new HttpTransport({
        endpoint: RPC_ENDPOINT,
      }),
      shardId: 1,
    });
    
    const block = await client.getBlockByHash(HASH);
  3. Understand =nil; multi-currency mechanism

    =nil; provides a default currency distributed by the Faucet contract. Additionally, it supports a multi-currency mechanism where any account (smart contract) can be paid in arbitrary currencies.

    Key constraints:

    • Currency Creation: Handled by a special precompiled contract called Minter.
    • Ownership: A contract can own only one currency. The currency ID is derived from the owner's address.
    • Minting: Only the owner of a currency can mint it.
    • Usage Limits: Custom currencies can be transferred between accounts but cannot be used to pay for essential network operations, such as deploying contracts or sending asynchronous calls.
  4. Understand FeeCredit and Value in nil messages

    In nil, every message uses two fields to handle gas and value:

    1. FeeCredit: The amount of nil base tokens allocated for message execution. Unlike Ethereum, there is no base or premium fee; FeeCredit is the gas limit (maximum gas the sender is willing to pay) multiplied by the gas price of the specific shard. It is an estimate, not a precise fee.
    2. Value: The amount of tokens transferred directly to the receiving address. These tokens are debited to the receiver and are not used for execution.

    Caveat: If a message is sent to a non-payable function with a non-zero Value, the execution will revert because the contract cannot accept the tokens.

  5. Understand the Account model in nil

    In the nil network, an account is the minimal unit of data used for sharding. An account is composed of four primary elements: an address, a balance, a storage root, and the hash of its source code. The system distributes accounts across execution shards, while a dedicated consensus shard maintains the mapping of which accounts belong to which shards.
  6. Use MetaMaskSigner to sign data in the browser

    The MetaMaskSigner class allows for signing data using a MetaMask wallet. This signer is only compatible with browser environments and implements the ISigner interface.
    import { MetaMaskSigner } from '@nilfoundation/niljs';
    
    const signer = new MetaMaskSigner();
  7. IReceipt type definition

    The IReceipt interface represents a transaction receipt in the NIL ecosystem. It contains metadata about the block, gas usage, execution success, and associated logs and messages.
    type IReceipt = {
      blockHash: string;
      blockNumber: number;
      bloom: string;
      contractAddress: string;
      gasPrice?: string; // optional
      gasUsed: string;
      includedInMain: boolean;
      logs: ILog[];
      messageHash: Hex;
      msgIndex: number;
      outMessages: Hex[] | null;
      outputReceipts: (IReceipt | null)[] | null;
      shardId: number;
      success: boolean;
    };
  8. Use the ISigner interface to manage keys and sign data

    The ISigner interface defines the standard set of methods required for a Signer class in the niljs library. It provides functionality to retrieve the account address, the public key, and to cryptographically sign data.
  9. Understand the =nil; network architecture and ZKP flow

    The =nil; architecture utilizes a tiered consensus and proof system to achieve finality on Ethereum. Execution shards generate Zero-Knowledge Proofs (ZKPs) for state changes using a Sync HotStuff-based protocol for local consensus. These proofs are then verified via a HotStuff2-based global consensus protocol. Finally, the main shard aggregates these ZKPs into a single 'master' ZKP, which is transmitted to Ethereum to verify the global state and finalize transactions.