Skip to content

Configuration

To configure SatoshiKit, you need to create a midl config using createMidlConfig from @midl/satoshi-kit. This config will automatically set up the connectors for you.

ts
import { createMidlConfig } from "@midl/satoshi-kit";
import { regtest } from "@midl/core";


export const midlConfig = createMidlConfig({
  networks: [regtest],
  persist: true,
}) as Config;

By default, createMidlConfig sets up the following connectors:

  • xverseConnector (marked as partner)
  • phantomConnector
  • leatherConnector
  • bitgetConnector
  • unisatConnector
  • okxConnector

You can add other connectors (like magicEdenConnector) by passing a custom connectors array.

If you want to use SatoshiKit with a specific wallet, you can pass the connectors option to createMidlConfig. This will allow you to specify which wallets you want to use with SatoshiKit.

ts
import { createMidlConfig } from "@midl/satoshi-kit";
import { regtest } from "@midl/core";
import { xverseConnector } from "@midl/connectors";

export const midlConfig = createMidlConfig({
  networks: [regtest],
  persist: true,
  connectors: [xverseConnector()],
}) as Config;

TIP

You can also set custom metadata for the connectors by passing metadata option to the connector function. This metadata will be used to display the wallet in a specific category in the wallet list.

ts
import { createMidlConfig } from "@midl/satoshi-kit";
import { regtest } from "@midl/core";
import { xverseConnector } from "@midl/connectors";

export const midlConfig = createMidlConfig({
  networks: [regtest],
  persist: true,
  connectors: [
    xverseConnector({
      metadata: {
        group: "popular",
      },
    }),
  ],
}) as Config;

SatoshiKitProvider

SatoshiKitProvider is a React context provider that allows you to use SatoshiKit in your application. It provides the necessary context for the components to work correctly.

You can specify the purposes, authenticationAdapter, and config props to customize the behavior of SatoshiKitProvider.

Props

NameTypeDescription
purposesAddressPurpose[] (optional)The purposes for which addresses will be generated. This is an array of AddressPurpose values. If not provided, defaults to [AddressPurpose.Payment, AddressPurpose.Ordinals].
authenticationAdapterAuthenticationAdapter (optional)An optional authentication adapter to handle user authentication. If not provided, no authentication flow is used.
configConfig (optional)The midl config object. If not provided, SatoshiKit will use the default config.

For details on implementing the authenticationAdapter, see the Authentication documentation.

tsx
import { SatoshiKitProvider } from "@midl/satoshi-kit";
import { AddressPurpose } from "@midl/core";
import { midlConfig } from "./config";

export const App = () => {
    return (
        <SatoshiKitProvider config={midlConfig} purposes={[AddressPurpose.Payment]}>
            {/* Your app components */}
        </SatoshiKitProvider>
    );
};

useSatoshiKit

useSatoshiKit lets you access the current SatoshiKit context values (config, purposes, authentication adapter).

tsx
import { useSatoshiKit } from "@midl/satoshi-kit";

const { config, purposes, authenticationAdapter } = useSatoshiKit();

Released under the MIT License