Skip to main content
Actions SDK is still under construction and not ready for production use! This guide is meant for early testing purposes only.
The Actions SDK is an open source Typescript development toolkit that simplifies the act of integrating DeFi into your application.

How it works

Here’s a breakdown of what’s under the hood:
  • Modular Providers: Actions is built with a set of core adapters called “Providers”. Providers let you to pick an choose the right services and protocols for your use-case.
  • Embedded Wallets: Actions supports popular embedded wallet providers, allowing your users to access DeFi with email authentication flows alone.
  • Configure Actions: Extend your embedded wallet with DeFi actions like Lend, Borrow, Swap, and Pay. Set multiple providers for each Action to choose the best markets across DeFi.
  • Customize assets & chains: Allow and block assets, markets, chains, and protocols from your application from a single config.

Installation

Install the Actions SDK in your project:
npm install @eth-optimism/actions-sdk

Choose a Wallet Provider

Actions works with both frontend and backend wallets depending on your needs:
  • Frontend
  • Backend
Select a wallet provider:
  • Privy
  • Turnkey
  • Dynamic
Install and setup Privy.Configure Wallet ProviderGive your embedded wallets the ability to take Action:
import { actions } from './config'
import { useWallets } from '@privy-io/react-auth'

// PRIVY: Fetch wallet
const { wallets } = useWallets()
const embeddedWallet = wallets.find(
  (wallet) => wallet.walletClientType === 'privy',
)

// ACTIONS: Let wallet make onchain Actions
const wallet = await actions.wallet.toActionsWallet({
  connectedWallet: embeddedWallet,
})
Configure Smart WalletsOptionally, create signers for smart wallets you control:
import { actions } from './config'
import { useWallets } from '@privy-io/react-auth'

// PRIVY: Fetch wallet
const { wallets } = useWallets()
const embeddedWallet = wallets.find(
  (wallet) => wallet.walletClientType === 'privy',
)

// ACTIONS: Create signer from hosted wallet
const signer = await actions.wallet.createSigner({
  connectedWallet: embeddedWallet,
})

// ACTIONS: Create smart wallet
const { wallet } = await actions.wallet.createSmartWallet({
  signer: signer
})

Create your ActionsConfig

Create your Actions configuration to define which protocols, chains, and assets to support. Configure a wallet provider:
import type { WalletConfig } from '@eth-optimism/actions-sdk'

const walletConfig: WalletConfig = {
  hostedWalletConfig: {
    provider: {
      type: 'privy', // your provider chosen in previous step
    },
  },
  smartWalletConfig: {
    provider: {
      type: 'default',
      attributionSuffix: 'actions',
    },
  },
}
Configure a lend provider with LendConfig:
import type { LendConfig } from '@eth-optimism/actions-sdk'
import { USDC, ETH, WBTC } from '@eth-optimism/actions-sdk/assets'
import { USDCMorphoMarket } from './actions/markets'

const lendConfig: LendConfig = {
  type: 'morpho',
  assetAllowlist: [USDC, ETH, WBTC],
  assetBlocklist: [],
  marketAllowlist: [USDCMorphoMarket],
  marketBlocklist: [],
}
Configure a borrow provider with BorrowConfig:
import type { BorrowConfig } from '@eth-optimism/actions-sdk'
import { USDC, ETH, WBTC } from '@eth-optimism/actions-sdk/assets'
import { USDCMorphoMarket } from './actions/markets'

const borrowConfig: BorrowConfig = {
  type: 'morpho',
  assetAllowlist: [USDC, ETH, WBTC],
  assetBlocklist: [],
  marketAllowlist: [USDCMorphoMarket],
  marketBlocklist: [],
}
Configure a swap provider with SwapConfig:
import type { SwapConfig } from '@eth-optimism/actions-sdk'
import { USDC, ETH, WBTC } from '@eth-optimism/actions-sdk/assets'

const swapConfig: SwapConfig = {
  type: 'uniswap',
  defaultSlippage: 100, // 100 bips or 1%
  assetAllowList: [USDC, ETH, WBTC],
  assetBlocklist: [],
}
Configure supported chains:
import { optimism, base } from 'viem/chains'

// Define any EVM chain
const OPTIMISM = {
  chainId: optimism.id,
  rpcUrls: env.OPTIMISM_RPC_URL,
  bundler: { // Bundle and sponsor txs with a gas paymaster
    type: 'simple' as const,
    url: env.OPTIMISM_BUNDLER_URL,
  },
}

const BASE = {
  chainId: base.id,
  rpcUrls: env.BASE_RPC_URL,
  bundler: { // Bundle and sponsor txs with a gas paymaster
    type: 'simple' as const,
    url: env.BASE_BUNDLER_URL,
  },
}

const chains = [OPTIMISM, BASE]
Finally, bring it all together and initialize Actions:
export const actions = createActions({
  wallet: walletConfig,
  lend: lendConfig,
  borrow: borrowConfig,
  swap: swapConfig,
  chains,
})

Using Actions

Once configured, you can use Actions to perform DeFi operations:
import { USDC, ETH, USDT } from '@eth-optimism/actions-sdk/assets'
import { ExampleMarket } from '@/actions/markets'

// Enable asset lending in DeFi
const lendReceipt = await wallet.lend.openPosition({
  amount: 1,
  asset: USDC,
  ...ExampleMarket
})

// Manage user market positions
const lendPosition = await wallet.lend.getPosition(market)

// Fetch wallet balance
const balance = await wallet.getBalance()

// ⚠️ COMING SOON
const borrowReceipt = await wallet.borrow.openPosition({
  amount: 1,
  asset: USDT,
  ...market
})

// ⚠️ COMING SOON
const swapReceipt = await wallet.swap.execute({
  amountIn: 1,
  assetIn: USDC,
  assetOut: ETH,
})

// ⚠️ COMING SOON
const sendReceipt = await wallet.send({
  amount: 1,
  asset: USDC,
  to: 'vitalik.eth',
})

Next Steps