STP SDK
Fabric currently provides a typescipt SDK targetting wagmi/wagmi-core. The source is avilable on GitHub (opens in a new tab)
Installation
npm i @withfabric/protocol-sdks
Setup
Since the SDK depends on wagmi, all functions leverage a wagmi config Object, which must set via a configuration call:
import { createConfig } from '@wagmi/core';
import { configureFabricSDK } from '@withfabric/protocol-sdks';
// Create wagmi configuration
const config = return createConfig({
// ...
});
// Configure the SDK to use your wagmi configuration
configureFabricSDK({ wagmiConfig: config });
Mint Example
import {
prepareMint,
} from '@withfabric/protocol-sdks/stpv2';
const mint = await prepareMint({
contractAddress: '0x...',
amount: 100_000n,
})
const receipt = await mint();
Usage in a Dapp (React + Wagmi)
import { useCallback } from 'react';
import {
prepareMint,
} from '@withfabric/protocol-sdks/stpv2';
export function MintButton({ contractAddress, chainId, amount } : {
contractAddress: `0x${string}`,
chainId?: number,
amount: bigint,
}) {
const mintTxn = useCallback(async () => {
// This can throw an error if the mint isn't possible, etc
return await prepareMint({
contractAddress,
amount,
chainId,
});
}, [contractAddress, chainId, amount]);
// Note: This is a simple example. You may want to add error handling, connection checks, processing states, etc.
return <Button
onClick={mintTxn}
text="Mint"
/>;
}
Examples for other actions can be found throughout the documentation.
Questions? Feedback?
Reach out on Telegram (opens in a new tab)