@okcontract/sdk
Version:
One-stop-shop permissionless SDK for building any blockchain frontend
76 lines (75 loc) • 3.21 kB
TypeScript
import { type Abi, type GetContractReturnType } from "viem";
import type { AnyCell, MapCell, ValueCell } from "@okcontract/cells";
import { type ABI, type ABIExtra, type AnonContractQueryType, type AnyTokenQuery, type ContractQueryType, type NFTQueryType, type OKToken, type SmartContract, type TokenQueryType } from "@okcontract/coredata";
import { type Environment, type ValueDefinition } from "@okcontract/lambdascript";
import type { ChainAddress, ChainType } from "@okcontract/multichain";
import type { OKPage } from "./instance";
import { type PivotFunction, type PivotView } from "./pivot";
import { type ContractFunctionValues } from "./vrw";
export type ViemContract = GetContractReturnType<Abi | unknown[], {
public?: never;
wallet: never;
}, `0x${string}`, string> & {
read: {
[key: string]: (...args: unknown[]) => unknown;
};
};
export type OKContractInitArgs = {
addr: ChainAddress;
dcToken?: OKToken;
dcContract?: SmartContract;
};
export type AnyContractQuery = ContractQueryType | AnonContractQueryType<string> | AnyTokenQuery;
export type DataOfContractQuery<Query extends AnyContractQuery> = Query extends ContractQueryType ? SmartContract : Query extends TokenQueryType ? OKToken : Query extends NFTQueryType ? OKToken : SmartContract;
export declare class OKContract<Query extends AnyContractQuery> {
private _instance;
private _proxy;
private _localRPC;
private _core;
readonly query: AnyCell<Query>;
readonly address: AnyCell<ChainAddress>;
readonly wantedChain: AnyCell<ChainType>;
readonly chain: AnyCell<ChainType>;
readonly chains: AnyCell<Map<ChainType, ChainAddress<"evm">>>;
readonly data: AnyCell<DataOfContractQuery<Query>>;
readonly isAnon: MapCell<boolean, true>;
readonly abi: AnyCell<ABI>;
readonly parsedAbi: AnyCell<Abi>;
readonly abix: AnyCell<ABIExtra> | undefined;
readonly VRW: AnyCell<ContractFunctionValues>;
readonly env: AnyCell<Environment>;
readonly pivot: AnyCell<PivotView>;
readonly P: AnyCell<PivotFunction[]>;
readonly pEnv: AnyCell<ValueDefinition[]>;
readonly values: AnyCell<ValueDefinition[]>;
readonly pArgs: ValueCell<unknown>;
constructor(instance: OKPage, q: AnyCell<Query>, wantedChain: AnyCell<ChainType>, options?: {
dcToken?: AnyCell<OKToken>;
dcContract?: AnyCell<SmartContract>;
abi?: Abi;
restrictVRW?: string[];
});
/**
* Prints the ABI as string.
*/
ABIString: () => Promise<string>;
error: () => Promise<string>;
}
/**
* The OKContractManager class is responsible for managing and caching
* instances of OKContract objects.
* It provides a method to retrieve or create an OKContract instance
* based on the provided ChainAddress and optional contract or token data.
*/
export declare class OKContractManager {
private _instance;
private _cache;
private _id;
private _count;
readonly stats: AnyCell<string>;
readonly chain: AnyCell<ChainType>;
constructor(instance: OKPage, chain?: ValueCell<string>);
get<Q extends AnyContractQuery>(q: AnyCell<Q>, options?: {
abi?: Abi;
}): AnyCell<OKContract<Q> | null>;
}