The Boost V2 Docs are under active development and will be subject to changes.

This code snippet briefly illustrates a few core concepts of @boostxyz/sdk

import { BoostCore, EventAction, SimpleAllowList } from '@boostxyz/sdk'
// or using subpath exports, if you prefer
import { BoostCore } from '@boostxyz/sdk/BoostCore'
import { EventAction } from '@boostxyz/sdk/Actions/EventAction'
import { SimpleAllowList } from '@boostxyz/sdk/AllowLists/SimpleAllowList'
import { SimpleDenyList } from '@boostxyz/sdk/AllowLists/SimpleDenyList'

// Peer dependencies
import { createConfig, http } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

// You'll likely want the following if you're in a Node environment
import { createWalletClient, http, publicActions } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet } from 'viem/chains'

// Create your Wagmi config. If using `React` or `Vue`, you can also use the [Wagmi `useConfig` API](https://wagmi.sh/react/api/hooks/useConfig)
let config = createConfig({
  chains: [sepolia],
  transports: {
    [sepolia.id]: http('https://sepolia.example.com'),
  },
})

// If you are in a Node environment and signing transactions, you'll additionally want to configure a [Viem Local Account](https://viem.sh/docs/accounts/local) and a [Viem client](https://viem.sh/docs/clients/intro)
const account = privateKeyToAccount('PRIVATE_KEY')
config = createConfig({
  ssr: true,
  chains: [sepolia],
  transports: {
    [sepolia.id]: http('https://sepolia.example.com'),
  },
  client: ({ chain }) => {
    return createWalletClient({
      account,
      chain,
      transport: http()
    }).extend(publicActions)
  },
})

// Instantiate a new Boost Core, supplying your config and local account, if needed.
const core = new BoostCore({ config, ...(!!account && { account }) })

// Get a single Boost, this will automatically instantiate the Boost's core components.
const boost = await core.getBoost(0n)
// or, if you'd like to avoid extra read calls or just want the on chain representation,
await core.readBoost(0n)

// a Boost is comprised of several components
const validator: SignerValidator = boost.validator
const budget: ManagedBudget = boost.budget
const allowList: SimpleAllowList | SimpleDenyList = boost.allowList
const action: EventAction = boost.action
const incentives: Array<AllowListIncentive | CGDAIncentive | ERC20Incentive | PointsIncentive> = boost.incentives

// Some Boost components can be of a few different types...
if(boost.allowList instanceof SimpleAllowList) {
  await boost.setAllowed(
    ['0xdeadb33f'], [true]
  )
}
// so you can infer it for dynamic functionality
if(boost.allowList instanceof SimpleDenyList) {
  await boost.setDenied(
    ['0xdeadb33f'], [false]
    // For every public method that reads or writes, the last parameter is an optional object where you can supply additional values for the operation if desired.
    // For more information, see:
    // https://wagmi.sh/core/api/actions/readContract
    // https://wagmi.sh/core/api/actions/writeContract
    {
      chainId: 31137,
      blockNumber: 1337n,
      blockTag: 'latest',
      dataSuffix: '0x',
      account: privateKeyToAccount('DIFFERENT_KEY'),
      gas: 0n,
      nonce: 1,
      value: parseEther('0.01'),
      gasPrice: parseGwei('20'),
      maxFeePerGas: parseGwei('20'),
      maxPriorityFeePerGas: parseGwei('2'),
    }
  )
}

// if you need, you can access the ABI for any Boost component either of two ways
const abi = boost.allowList.abi
import { simpleAllowListAbi } from '@boostxyz/sdk/AllowLists/SimpleAllowList'

Targeting Specific Chains

The Boost SDK allows you to interact with the BoostCore and BoostRegistry contracts across different chains. You can specify which chain you want to target by including a chainId in the params object of your method calls.

// Target a boost with id of 3 on Base mainnet (chainId: 8453)
const boost = await core.getBoost(3n, { chainId: 8453 })

Always ensure that the protocol is deployed on the chain you’re targeting. Specifying a chainId for a network where the protocol isn’t deployed could result in degraded UX if, in the browser, the SDK attempts to switch chains to its default network and there’s no supporting chain configuration in your Wagmi/Viem client.

By specifying the chainId in the params, you ensure that the SDK targets the correct contracts for the specific network you are targetting.

The SDK uses the following process to determine which chain to interact with:

  1. It first attempts to use the contract address associated with the specified chainId passed in the params.
  2. If no address is found for the given chainId, it falls back to using the address for the connected account’s chain.
  3. If that also fails, it uses the address for the default chain set in the SDK config.