clarity-abitype
v0.4.0
Published
Strict TypeScript types for Stacks Clarity ABIs
Readme
clarity-abitype
Strict TypeScript types for Clarity ABIs. Provides utilities and type definitions for Clarity smart contract ABIs on the Stacks blockchain.
Documentation
Head to the documentation to read and learn more about the package.
Installation
npm install clarity-abitype
# or
pnpm add clarity-abitype
# or
yarn add clarity-abitypeUsage
import type {
ClarityAbiArgsToPrimitiveTypes,
ExtractAbiFunction,
ExtractAbiFunctionNames,
} from "clarity-abitype";
import { sip10Abi } from "clarity-abitype/abis";
type FunctionNames = ExtractAbiFunctionNames<typeof sip10Abi, "read_only">;
// ^? type FunctionNames = "get-balance" | "get-decimals" | "get-name" | "get-symbol" | ...
type TransferInputTypes = ClarityAbiArgsToPrimitiveTypes<
// ^? type TransferInputTypes = readonly [bigint, string, string, `0x${string}` | null]
ExtractAbiFunction<typeof sip10Abi, "transfer">["args"]
>;Works great for adding blazing fast autocomplete and type checking to functions, variables, or your own types. No need to generate types with third-party tools – just use your ABI and let TypeScript do the rest!
Credits
clarity-abitype initial implementation is based on the amazing work of abitype by wevm.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
