UNPKG

hang-sdk

Version:

Hang SDK is on a mission to help developers create DAPPs with ease and interact with Hang deployed smart contracts.

167 lines (165 loc) 5.5 kB
import events from "events"; import Web3 from "web3"; import { BigNumber } from "bignumber.js"; import { Contract } from "web3-eth-contract"; import { MerkleTree } from "merkletreejs"; import Web3Modal, { ICoreOptions } from "web3modal"; export const INFURA_ID = "d09bd1bc72e6427d80fa37e01481cd34"; export const MINT_STATUSES: { NOT_INITIATED: number; IN_PROGRESS: number; COMPLETED: number; }; export const CHAIN_CURRENCIES: { ethereum: string; solana: string; matic: string; }; export interface IChain { chainId: string; chainName: string; nativeCurrency: { name: string; symbol: string; decimals: number; }; rpcUrls: string[]; blockExplorerUrls: string[]; } export const networkMap: Record<number, IChain>; export const CONTRACT_PLATFORMS: { ETHEREUM: string; SOLANA: string; }; export const FORMATTED_ERRORS: { PROJECT_INFO_FETCH_ERROR: string; 'BASE_COLLECTION/CANNOT_MINT': string; 'BASE_COLLECTION/PURCHASE_DISABLED': string; 'BASE_COLLECTION/INSUFFICIENT_ETH_AMOUNT': string; 'BASE_COLLECTION/EXCEEDS_MAX_SUPPLY': string; 'BASE_COLLECTION/GAS_FEE_NOT_ALLOWED': string; 'BASE_COLLECTION/EXCEEDS_INDIVIDUAL_SUPPLY': string; 'BASE_COLLECTION/PRESALE_INACTIVE': string; 'BASE_COLLECTION/CANNOT_MINT_PRESALE': string; INSUFFICIENT_ETH_BALANCE: string; }; export const STG_HOST = "https://www.headliner.page"; export const PROD_HOST = "https://www.hang.xyz"; export interface ICrossMintOptions { presale: string; onsale: string; } export interface IProjectMetadata { contract: { abi: string; address: string; chain: string; chain_id: number; id: number; platform: string; whitelist: string[]; crossmint?: ICrossMintOptions; }; pad_no_minted: number; enable_crossmint_checkout: boolean; collection_label: string; info: { title: string; image: string; }; presale_price: string; price: string; } export interface IStateChangeEventParams { isReady: boolean; } export interface IErrorEventParams { type: keyof typeof FORMATTED_ERRORS; message: string; } export interface ITransactionSubmittedEventParams { transactionHash: string; } export interface ITransactionCompletedEventParams { receipt: any; } export interface IWalletConnectedEventParams { address: string; } type CUSTOM_EVENTS = { ERROR: IErrorEventParams; STATE_CHANGE: IStateChangeEventParams; TRANSACTION_COMPLETED: ITransactionCompletedEventParams; TRANSACTION_SUBMITTED: ITransactionSubmittedEventParams; WALLET_CONNECTED: IWalletConnectedEventParams; WALLET_CHANGED: null; }; interface CustomEvents { on<T extends keyof CUSTOM_EVENTS, R extends CUSTOM_EVENTS[T]>(event: T, listener: (params: R) => void): this; } declare class CustomEvents extends events.EventEmitter { constructor(); emit<T extends keyof CUSTOM_EVENTS, R extends CUSTOM_EVENTS[T]>(event: T, params: R): boolean; } export interface IHangCoreProps { debug?: boolean; slug: string; mode?: 'TEST' | 'PROD'; } export class HangCore { merkleRoot?: MerkleTree; contractInstance?: Contract; web3Instance: Web3; options: IHangCoreProps; events: CustomEvents; projectData?: IProjectMetadata; presaleActive: boolean; publicsaleActive: boolean; constructor(options: IHangCoreProps); fetchProjectMetadata(): Promise<void>; web3(web3: Web3): void; isPublicSaleActive: () => Promise<any>; isPresaleActive: () => any; getProofForAddress: (address: string) => { leaf: Buffer; proof: string[] | undefined; }; onPreSaleAllowList: (address: string) => any; fetchTotalMintable: () => Promise<number>; fetchTotalMinted: () => Promise<number>; maxMintPerAddress: () => Promise<number>; balanceOfAddress: (address: string) => Promise<number>; canMint: (address: string) => Promise<boolean | void>; fetchCurrentPrice: () => any; mintTo: (quantity: number | undefined, address: string) => Promise<any>; crossMint: (quantity?: number) => void; postConfirm: (error: any, transactionHash: string) => Promise<boolean | undefined>; getTransactionReceiptMined: (txHash: string, interval?: number) => any; fetchTotalMintedPadded: () => Promise<number>; fetchCurrentPriceFormatted: () => Promise<string>; crossMintEnabled: () => Promise<boolean>; walletBalance: (address: string) => Promise<string>; walletHasEnoughBalance: (address: string, totalCost: BigNumber) => Promise<boolean>; } export interface IHangWalletPluginOptions extends IHangCoreProps { web3ModalOptions?: Partial<ICoreOptions>; } export class HangWalletPlugin extends HangCore { accounts?: string[]; provider?: any; web3Modal: Web3Modal; constructor({ slug, web3ModalOptions, ...args }: IHangWalletPluginOptions); autoconnect: () => Promise<void>; connect: () => Promise<void>; connectToWeb3Modal: () => Promise<any>; clearWalletConnectKeys: () => void; onConnectComplete: () => Promise<void>; syncAccountAndContract: () => Promise<void>; fetchAccountData: () => Promise<void>; addProviderEvents: () => void; getCurrentWallet: () => string; requestChainSwitchIfNeeded: () => Promise<void>; mint(quantity?: number): Promise<void>; balanceOfCurrentWallet(): Promise<number>; } //# sourceMappingURL=types.d.ts.map