0.1.0-beta.8 • Published 1 year ago

@pikapool/sdk v0.1.0-beta.8

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
1 year ago

Pikapool TypeScript SDK

npm

Features

  • Craft EIP712-compliant Bid payloads
  • Submit Bid payloads to the Pikapool mempool
  • React hook simplifying the Bid creation and submission experience
  • Query Bids
  • Query Auctions
  • Create and manage Auctions

Install

yarn add @pikapool/sdk
# or
npm install @pikapool/sdk

Usage

Create & Submit Bid (React)

Check out our React Demo.

import { bids } from "@pikapool/sdk";

function BidComponent() {
  // your logic...
  const { 
    signAndSubmit,  // () => Promise<void>;
    isLoading,      // boolean;
    error,          // Error | null;
    receipt,        // BidReceipt | null;
    reset,          // () => void;
  } = bids.hooks.useBid(
    auctionName,    // Auction name
    auctionAddress, // Auction address (aka nft address)
    basePrice,      // Auction base price (per-nft)
    amount,         // Number of NFTs the user wishes to purchase
    tip,            // Amount user wishes to tip (per-nft)
    signer,         // An ethers.js JsonRpcSigner or Wallet
    optionOverrides // PikapoolOptionOverrides
  );
  // your logic...
}

interface BidReceipt {
  id: string;
  cid: string;
}

interface PikapoolOptionOverrides {
  settlementContract?: `0x${string}`;
  rpcUrl?: string;
}

Create & Submit Bid (Vanilla TypeScript)

import { bids } from "@pikapool/sdk";

function createAndSubmitBid() {
  // your logic...
  const typedData: TypedBidData = await createTypedData(
    auctionName,    // Auction name
    auctionAddress, // Auction address (aka nft address)
    basePrice,      // Auction base price (per-nft)
    amount,         // Number of NFTs the user wishes to purchase
    tip,            // Amount user wishes to tip (per-nft)
    bidder,         // Bidder address
    optionOverrides // PikapoolOptionOverrides
  );

  // Sign typedData in any EIP712-compliant way.
  // Example here using an ethers.js JsonRpcSigner.
  const sig: string = await signer._signTypedData(
    typedData.domain,
    typedData.types,
    typedData.message
  );

  const res: SubmitBidResponse = await submitBid(
  typedBidData,    // TypedBidData,
  signature,       // string
  optionOverrides, // PikapoolOptionOverrides
  );
  // your logic...
}

interface SubmitBidResponse {
  status: number;     // HTTP Response StatusCode
  body: {
    id?: string;      // New Bid ID
    cid?: string;     // New Bid Content ID (alpha - do not use)
    error?: string;   // Error message
  };
}

interface TypedBidData {
  primaryType: string;
  domain: {
    name: string;
    version: string;
    chainId: string;
    verifyingContract: `0x${string}`;
  };
  types: {
    Bid: {
      name: string;
      type: string;
    }[];
  };
  message: {
    auctionName: string;
    auctionAddress: `0x${string}`;
    bidder: string | undefined;
    amount: string;
    basePrice: string;
    tip: string;
  };
}

interface PikapoolOptionOverrides {
  settlementContract?: `0x${string}`;
  rpcUrl?: string;
}
0.1.0-beta.8

1 year ago

0.1.0-beta.7

1 year ago

0.1.0-beta.6

1 year ago

0.1.0-beta.5

1 year ago

0.1.0-beta.4

1 year ago

0.1.0-beta.3

1 year ago

0.1.0-beta.2

1 year ago

0.1.0-beta.1

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago