gill SDK

repository·master·Indexed 19 days ago

https://github.com/gillsdk/gill

A JavaScript/TypeScript client library for the Solana blockchain built on top of the @solana/kit (web3.js v2) ecosystem. It provides a developer-friendly interface for building Solana applications across Node, web, and mobile environments, featuring utilities for signer management, RPC connections, transaction building, and SPL token management.

Tokens
64.1K
Snippets
209
Records
265
Agent score
62%

What's inside gill

  1. Overview of @gillsdk/solana-pay

    master

    The @gillsdk/solana-pay package is a comprehensive toolkit for implementing the Solana Pay protocol in your application. It enables developers to handle the following core Solana Pay workflows:

    • Transfer Requests: Generate payment URLs for SOL or SPL token transfers, including support for reference tracking.
    • Transaction Requests: Implement interactive checkout flows by managing HTTPS endpoints for transaction requests.
    • URL Parsing: Parse and validate Solana Pay URLs with full type safety.
    • Response Handling: Fetch and validate merchant information and transaction data.
  2. Overview of gill

    master
    gill is a JavaScript/TypeScript client library designed for interacting with the Solana blockchain. It is built on top of the modern @solana/kit libraries by Anza, ensuring compatibility with the existing Solana ecosystem while providing enhanced developer ergonomics.
  3. Overview of @gillsdk/react hooks

    master
    The @gillsdk/react package provides a suite of React hooks designed for interacting with the Solana blockchain. These hooks are built on top of TanStack Query, which provides built-in features such as automatic caching, background refetching, and robust error handling. Hooks are categorized into Client Management, Data Fetching, and Transaction Handling.
  4. Overview of the gill sdk

    master

    The gill sdk is a JavaScript/TypeScript client library designed for interacting with the Solana blockchain. It is compatible with various environments, including Node.js, web browsers, and React Native.

    gill is built on top of the @solana/kit (formerly known as web3.js v2) libraries by Anza. Because it utilizes the same underlying types and functions, gill is fully compatible with @solana/kit.

  5. Overview of @gillsdk/react

    master

    @gillsdk/react is a React hooks library designed for interacting with the Solana blockchain. It is built on top of two core libraries:

    1. gill: A modern JavaScript/TypeScript library for Solana interaction.
    2. @tanstack/react-query: Provides asynchronous state management, including caching, background refetching, and optimistic updates.

    Key Features:

    • Type-safe hooks: Full TypeScript support for Solana data.
    • TanStack Query integration: Leverages React Query for robust data fetching.
    • Server component ready: Compatible with Next.js and other React Server Component frameworks.
    • Lightweight: Supports tree-shaking for minimal bundle sizes.
  6. Use Node-specific imports for server environments

    master

    When working in NodeJS server backends or serverless environments that require access to Node-specific APIs (like node:fs), use the gill/node entry point instead of the standard gill package.

    This provides specialized utilities for managing keypairs via the filesystem or environment variables.

    import { ... } from "gill/node"
  7. Use the original Token Program with the Token2022 client

    master

    Because the Token Extensions program (@solana-program/token-2022) is fully backwards compatible with the original Token Program, gill only ships the Token2022 client to reduce bundle size.

    To interact with the original Token Program, use the Token2022 client but provide the TOKEN_PROGRAM_ADDRESS as the program address for your instructions.

  8. Understanding TransactionSigner and KeyPairSigner

    master

    In gill, a TransactionSigner is an abstraction for any object capable of performing Solana signing operations. It can be "attached" to instructions and transactions.

    • TransactionSigner: The general interface/type required by most signing-related functions.
    • KeyPairSigner: The most common implementation of a TransactionSigner. It is a concrete signer that holds a keypair and can be passed to functions like createTransaction or instruction builders.
  9. Perform Optimistic Updates with TanStack Query

    master

    When performing actions like transfers, you can use queryClient.setQueryData to immediately update the UI with an estimated new balance before the transaction is confirmed on-chain. If the transaction fails, use queryClient.invalidateQueries to revert the UI to the actual state from the network.

    import { useBalance } from "@gillsdk/react";
    import { useQueryClient } from "@tanstack/react-query";
    
    export function OptimisticBalance({ address }: { address: string }) {
      const queryClient = useQueryClient();
      const { balance } = useBalance({ address });
    
      const handleTransfer = async (amount: bigint) => {
        // 1. Optimistically update the balance in the cache
        queryClient.setQueryData(["gill", "balance", address], (old: bigint) => old - amount);
    
        try {
          // 2. Perform the actual transaction...
          // await sendTransaction(...)
    
          // 3. Invalidate to sync with real on-chain state
          queryClient.invalidateQueries({
            queryKey: ["gill", "balance", address],
          });
        } catch (error) {
          // 4. Revert on error
          queryClient.invalidateQueries({
            queryKey: ["gill", "balance", address],
          });
        }
      };
    
      return <div>Balance: {balance?.toString()}</div>;
    }
  10. How to make Solana RPC calls using the .send() pattern

    master

    In gill, calling an RPC method on the rpc object does not immediately execute the request. You must call .send() on the resulting method object to dispatch the request to the provider and receive a response.

    Common practice is to destructure the value property from the response, as most Solana RPC responses wrap the payload in a value attribute.

    import { createSolanaClient } from "gill";
    
    const { rpc } = createSolanaClient({ urlOrMoniker: "devnet" });
    
    // Get slot
    const slot = await rpc.getSlot().send();
    
    // Get latest blockhash
    const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
    import { createSolanaClient } from "gill";
    
    const { rpc } = createSolanaClient({ urlOrMoniker: "devnet" });
    
    // get slot
    const slot = await rpc.getSlot().send();
    
    // get the latest blockhash
    const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
  11. Implement Dependent Queries in @gillsdk/react

    master

    To avoid unnecessary network requests, use the enabled property to create dependent queries. This allows you to wait for the result of one hook (e.g., useAccount) before triggering another (e.g., useTokenAccount).

    import { useAccount, useTokenAccount } from "@gillsdk/react";
    
    export function ConditionalTokenBalance({ address }: { address: string }) {
      const { account, isLoading: loadingAccount } = useAccount({
        address,
      });
    
      const { account: tokenAccount, isLoading: loadingToken } = useTokenAccount({
        mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
        owner: address,
        enabled: !!account, // Only fetch if account exists
      });
    
      if (loadingAccount) return <div>Checking account...</div>;
      if (!account) return <div>Account not found</div>;
      if (loadingToken) return <div>Loading token balance...</div>;
    
      return <div>USDC Balance: {tokenAccount?.data?.amount.toString()}</div>;
    }
  12. Understand Solana Pay Request Types

    master

    Solana Pay supports two distinct request types depending on your use case:

    1. Transfer Requests: Non-interactive payment URLs where all details (amount, label, etc.) are encoded directly in the URL.

      • Best for: Simple payments, invoices, and QR codes.
      • Requirement: No server required.
      • Example: solana:recipient?amount=1.5&label=Coffee+Shop
    2. Transaction Requests: Interactive URLs that point to an HTTPS endpoint.

      • Best for: Complex transactions, merchant checkouts, and dynamic pricing.
      • Requirement: Requires a server-side implementation to handle GET and POST requests.