bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 7쪽
on use! This
guide is meant for early testing purposes only.
</Warning>
The [Actions SDK](https://actions.money/) 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](https://actions.money/#wallet), 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:
<CodeGroup>
```bash npm theme={null}
npm install @eth-optimism/actions-sdk
```
```bash pnpm theme={null}
pnpm add @eth-optimism/actions-sdk
```
```bash yarn theme={null}
yarn add @eth-optimism/actions-sdk
```
```bash bun theme={null}
bun add @eth-optimism/actions-sdk
```
```bash deno theme={null}
deno add @eth-optimism/actions-sdk
```
</CodeGroup>
## Choose a Wallet Provider
Actions works with both frontend and backend wallets depending on your needs:
<Tabs>
<Tab title="Frontend">
Select a wallet provider:
<Tabs>
<Tab title="Privy">
**Set Up Privy**
Sign up for Privy and follow the full Privy installation [guide](https://docs.privy.io/basics/react/installation).
**Configure Wallet Provider**
Once you have set up Privy embedded wallets, pass them to Actions SDK:
```typescript theme={null}
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 Wallets**
Optionally, create signers for smart wallets you control:
```typescript theme={null}
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
})
```
</Tab>
<Tab title="Turnkey">
**Set Up Turnkey**
Sign up for Turnkey and follow the full Turnkey installation [guide](https://docs.turnkey.com/sdks/react/getting-started).
**Configure Wallet Provider**
Once you have set up Turnkey embedded wallets, pass them to Actions SDK:
```typescript theme={null}
import { useTurnkey, WalletSource } from "@turnkey/react-wallet-kit"
import { actions, USDC, ExampleMarket } from './config'
// Fetch Turnkey wallet
const { wallets, httpClient, session } = useTurnkey()
const embeddedWallet = wallets.find(
(wallet) =>
wallet.accounts.some(
(account) => account.addressFormat === 'ADDRESS_FORMAT_ETHEREUM',
) && wallet.source === WalletSource.Embedded,
)
const walletAddress = embeddedWallet.accounts[0].address
// Convert to Actions wallet
const wallet = await actions.wallet.toActionsWallet({
client: httpClient,
organizationId: session.organizationId,
signWith: walletAddress,
})
// Wallet can now take action
const receipt = await wallet.lend.openPosition({
amount: 100,
asset: USDC,
...ExampleMarket
})
```
**Configure Smart Wallets**
Optionally, create signers for smart wallets you control:
```typescript theme={null}
import { useTurnkey, WalletSource } from "@turnkey/react-wallet-kit"
import { actions } from './config'
// Fetch Turnkey wallet
const { wallets, httpClient, session } = useTurnkey()
const embeddedWallet = wallets.find(
(wallet) =>
wallet.accounts.some(
(account) => account.addressFormat === 'ADDRESS_FORMAT_ETHEREUM',
) && wallet.source === WalletSource.Embedded,
)
const walletAddress = embeddedWallet.accounts[0].address
// Create signer
const signer = await actions.wallet.createSigner({
client: httpClient,
organizationId: session.organizationId,
signWith: walletAddress,
})
// Create smart wallet
const { wallet } = await actions.wallet.createSmartWallet({
signer: signer
})
```
</Tab>
<Tab title="Dynamic">
**Set Up Dynamic**
Sign up for Dynamic and follow the full Dynamic installation [guide](https://www.dynamic.xyz/docs/wallets/embedded-wallets/mpc/setup).
**Configure Wallet Provider**
Once you have set up Dynamic embedded wallets, pass them to Actions SDK:
```typescript theme={null}
import { useDynamicContext } from "@dynamic-labs/sdk-react-core"
import { actions, USDC, ExampleMarket } from './config'
// Fetch Dynamic wallet
const { primaryWallet } = useDynamicContext()
// Convert to Actions wallet
const wallet = await actions.wallet.toActionsWallet({
wallet: primaryWallet,
})
// Wallet can now take action
const receipt = await wallet.lend.openPosition({
amount: 100,
asset: USDC,
...ExampleMarket
})
```
**Configure Smart Wallets**
Optionally, create signers for smart wallets you control:
```typescript theme={null}
import { useDynamicContext } from "@dynamic-labs/sdk-react-core"
import { actions } from './config'
// Fetch Dynamic wallet
const { primaryWallet } = useDynamicContext()
// Create signer
const signer = await actions.wallet.createSigner({
wallet: primaryWallet
})
// Create smart wallet
const { wallet } = await actions.wallet.createSmartWallet({
signer: signer
})
```
</Tab>
</Tabs>
</Tab>
<Tab title="Backend">
Select a wallet provider:
<Tabs>
<Tab title="Privy">
**Set Up Privy**
Sign up for Privy and follow the full Privy installation [guide](https://docs.privy.io/basics/nodeJS/installation).
**Configure Wallet Provider**
Once you have set up Privy embedded wallets, pass them to Actions SDK:
```typescript theme={null}
import { actions } from './config'
import { PrivyClient } from '@privy-io/node'
// PRIVY: Create wallet
const privyClient = new PrivyClient(env.PRIVY_APP_ID, env.PRIVY_APP_SECRET)
const privyWallet = await privyClient.wallets().create({
chain_type: 'ethereum',
owner: { user_id: 'privy:did:xxxxx' },
})
// ACTIONS: Let wallet make onchain Actions
const wallet = await actions.wallet.toActionsWallet({
walletId: privyWallet.id,
address: privyWallet.address,
})
```
**Configure Smart Wallets**
Optionally, create signers for smart wallets you control:
```typescript theme={null}
import { actions } from './config'
import { PrivyClient } from '@privy-io/node'
import { getAddress } from 'viem'
const privyClient = new PrivyClient(env.PRIVY_APP_ID, env.PRIVY_APP_SECRET)
// PRIVY: Create wallet
const privyWallet = await privyClient.wallets().create({
chain_type: 'ethereum',
owner: { user_id: 'privy:did:xxxxx' },
})
// ACTIONS: Create signer
const signer = await actions.wallet.createSigner({
walletId: privyWallet.id,
address: getAddress(privyWallet.address),
})
// ACTIONS: Create smart wallet
const { wallet } = await actions.wallet.createSmartWallet({
signer: signer
})
```
</Tab>
<Tab title="Turnkey">
**Set Up Turnkey**
Sign up for Turnkey and follow the full Turnkey installation [guide](https://docs.turnkey.com/sdks/javascript-server).
**Configure Wallet Provider**
Once you have set up Turnkey embedded wallets, pass them to Actions SDK:
```typescript theme={null}
import { Turnkey } from '@turnkey/sdk-server'
import { actions, USDC, ExampleMarket } from './config'
const turnkeyClient = new Turnkey({
apiBaseUrl: 'https://api.turnkey.com',
apiPublicKey: process.env.TURNKEY_API_KEY,
apiPrivateKey: process.env.TURNKEY_API_SECRET,
defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
})
// Create Turnkey wallet
const turnkeyWallet = await turnkeyClient.apiClient().createWallet({
walletName: 'ETH Wallet',
accounts: [{
curve: 'CURVE_SECP256K1',
pathFormat: 'PATH_FORMAT_BIP32',
path: "m/44'/60'/0'/0/0",
addressFormat: 'ADDRESS_FORMAT_ETHEREUM',
}],
})
// Convert to Actions wallet
const wallet = await actions.wallet.toActionsWallet({
organizationId: turnkeyWallet.activity.organizationId,
signWith: turnkeyWallet.addresses[0],
})
// Wallet can now take action
const receipt = await wallet.lend.openPosition({
amount: 100,
asset: USDC,
...ExampleMarket
})
```
**Configure Smart Wallets**
Optionally, create signers for smart wallets you control:
```typescript theme={null}
import { Turnkey } from '@turnkey/sdk-server'
import { actions } from './config'
const turnkeyClient = new Turnkey({
apiBaseUrl: 'https://api.turnkey.com',
apiPublicKey: process.env.TURNKEY_API_KEY,
apiPrivateKey: process.env.TURNKEY_API_SECRET,
defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
})
// Create Turnkey wallet
const turnkeyWallet = await turnkeyClient.apiClient().createWallet({
walletName: 'ETH Wallet',
accounts: [{
curve: 'CURVE_SECP256K1',
pathFormat: 'PATH_FORMAT_BIP32',
path: "m/44'/60'/0'/0/0",
addressFormat: 'ADDRESS_FORMAT_ETHEREUM',
}],
})
// Create signer
const signer = await actions.wallet.createSigner({
organizationId: turnkeyWallet.activity.organizationId,
signWith: turnkeyWallet.addresses[0],
})
// Create smart wallet
const { wallet } = await actions.wallet.createSmartWallet({
signer: signer
})
```
</Tab>
</Tabs>
</Tab>
</Tabs>
## Create your ActionsConfig
Follow the [Configuring Actions](/app-developers/guides/configuring-actions) guide to define which protocols, chains, and assets to support.
## Take Action
Once configured, you can use Actions to perform DeFi operations:
```typescript theme={null}
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
* [Configure Actions](/app-developers/guides/configuring-actions) to customize protocols, chains, and assets
* Check out the [Actions demo](https://actions.money/earn) for a complete example application
# App developer quickstart
Source: https://docs.optimism.io/app-developers/quickstarts/get-started
Get testnet ETH, deploy your first contract to OP Sepolia, and bridge assets - your first steps on the Superchain.
OP Stack chains are [EVM equivalent](/op-stack/protocol/differences): everything you know from Ethereum works here, and everything you build here works across the OP Stack ecosystem.
This quickstart takes you from zero to a deployed contract on the OP Sepolia testnet, using only free testnet funds.
<Info>
No real funds are needed at any point — everything below runs on testnets.
</Info>
## Before you start
You'll need:
* A wallet you control (any EVM wallet works; you'll export or generate a private key for testnet use only).
* A terminal with `curl` available.
<Warning>
Use a fresh, testnet-only private key for tutorials. Never paste a key that holds real funds into a terminal.
</Warning>
<Steps>
<Step title="Get testnet ETH">
Grab free OP Sepolia ETH from the [Superchain Faucet](https://console.optimism.io/faucet).
Other options are listed on the [testnet faucets page](/app-developers/tools-sdks/faucets).
</Step>
<Step title="Connect to OP Sepolia">
OP Sepolia's public RPC endpoint is `https://sepolia.optimism.io` and its chain ID is `11155420`.
Verify you can reach it:
```bash theme={null}
curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \
https://sepolia.optimism.io
```
Expected result: `{"jsonrpc":"2.0","id":1,"result":"0xaa37dc"}` (`0xaa37dc` = 11155420).
For other networks and production-grade endpoints, see [network information](/op-mainnet/network-information/connecting-to-op) and [RPC providers](/app-developers/reference/rpc-providers).
</Step>
<Step title="Deploy your first contract">
Follow the [Deploy a contract to OP Sepolia](/app-developers/tutorials/deploy-a-contract) tutorial.
It walks you through installing Foundry, deploying a small `Greeter` contract, and reading and writing to it from the command line — the same workflow you'd use on Ethereum.
</Step>
<Step title="Bridge ETH between L1 and L2 (optional)">
Apps often need to move assets between Ethereum and an OP Stack chain.
Start with [Bridging basics](/app-developers/guides/bridging/basics) to understand the model, then follow the [Bridging ETH with Viem](/app-developers/tutorials/bridging/cross-dom-bridge-eth) tutorial to do a Sepolia → OP Sepolia deposit programmatically.
</Step>
</Steps>
## Where to go next
<CardGroup>
<Card title="Build apps on OP Stack chains" href="/app-developers/guides/building-apps">
Development workflow, tooling, and what (little) is different from Ethereum.
</Card>
<Card title="Test your apps" href="/app-developers/guides/testing-apps">
Test against OP Stack chains locally and in CI.
</Card>
<Card title="Go cross-chain with interop" href="/app-developers/guides/interoperability/get-started">
Build apps that span multiple Superchain chains.
</Card>
<Card title="Integrate DeFi with the Actions SDK" href="/app-developers/quickstarts/actions">
Lend, borrow, and swap with lightweight, type-safe modules (early preview — not production-ready).
</Card>
</CardGroup>
<Info>
**Running your app in production**
A production application depends on infrastructure your team does not run: RPC endpoints that hold up under real traffic (the public endpoints are rate-limited and not built for production), bridges your users rely on, and a chain whose operator keeps sequencing, upgrades, and incident response going around the clock. These docs cover building and testing. If your application is growing toward dedicated blockspace of its own, [OP Enterprise](https://optimism.io/op-enterprise?utm_source=docs\&utm_medium=docs\&utm_campaign=op-enterprise) offers managed and supported paths to running a chain. These docs stay the reference for what you build either way. OP Enterprise is Optimism's managed offering.
</Info>
## Need help?
* Ask a question or report documentation issues on the [Optimism monorepo issue tracker](https://github.com/ethereum-optimism/optimism/issues).
# Integrating wallets
Source: https://docs.optimism.io/app-developers/reference/actions/integrating-wallets
Understand the wallet options Actions SDK supports, embedded wallet providers, gas sponsorship, and smart wallets.
## Which wallets are right for my use case?
In order to let your users access DeFi, they will need an <Tooltip href="https://ethereum.org/developers/docs/evm/">EVM</Tooltip>-compatible wallet. There are plenty of considerations when selecting a wallet schema that works for you:
* Who will maintain custody of funds?
* What permissions must exist for my use case?
* Where in my stack should transaction signatures originate?
* How can my users on and off ramp funds?
Actions SDK supports popular [embedded wallet providers](#embedded-wallet-providers) to address all of these questions while remaining flexible to your use case.
## Embedded Wallet Providers
Embedded wallet providers give your users the ability to sign onchain transactions through your app's existing email authentication and authorization flows.
Actions works with:
<CardGroup>
<Card title="Privy" href="https://www.privy.io/" icon="https://mintcdn.com/optimism-373f39ad/9zyR2ZwcL-ncDc-N/public/img/actions/Privy.png?fit=max&auto=format&n=9zyR2ZwcL-ncDc-N&q=85&s=72e628e7c7e8804636d7edc65092e06c" />
<Card title="Turnkey" href="https://www.turnkey.com/" icon="https://mintcdn.com/optimism-373f39ad/9zyR2ZwcL-ncDc-N/public/img/actions/turnkey.png?fit=max&auto=format&n=9zyR2ZwcL-ncDc-N&q=85&s=d963f9d75de9fcb9ad69c38acf61f0b1" />
<Card title="Dynamic" href="https://www.dynamic.xyz/" icon="https://mintcdn.com/optimism-373f39ad/9zyR2ZwcL-ncDc-N/public/img/actions/dynamic.png?fit=max&auto=format&n=9zyR2ZwcL-ncDc-N&q=85&s=a34b37a0f6b1866583200bef641864f1" />
</CardGroup>
## Gas Sponsorship
Signing and sending onchain transactions requires gas, or fee payment, which adds [additional overhead](/app-developers/guides/transactions/estimates) for you and friction for users.
Actions supports gas sponsorship via a combination of smart contract wallets and [paymasters](https://eips.ethereum.org/EIPS/eip-7677). First, configure a paymaster in the chain config by specifying a bundler url. Now, any transactions submitted via an actions SmartWallet on that chain will automatically use your paymaster, therefore eliminating the need for the wallet to pay gas.
## Connect your wallet to Actions
Regardless of where and how transactions are signed, Actions has you covered.
Once you've chosen a wallet provider, follow the guide on [connecting a wallet to Actions SDK](/app-developers/guides/connect-wallet-to-actions) to pass the provider wallet to Actions and start calling Actions functions like Lend, Borrow, Swap, and Pay.
## Smart wallets & signers
In addition to using embedded provider wallets directly, Actions [supports the creation](/app-developers/quickstarts/actions#choose-a-wallet-provider) of custom smart contract wallets. This additional wallet type is separate from, but still controlled by the owner of the embedded wallet.
If you [configure it](/app-developers/guides/configuring-actions), Actions will deploy a [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) compliant [Coinbase Smart Wallets](https://github.com/coinbase/smart-wallet) on the chains you've chosen to support.
Once created, an embedded wallet can be added as a signer on the smart wallet, capable of signing transactions on behalf of the Smart Wallet.
See [Wallet Documentation](/app-developers/reference/actions/wallet-definitions) for additional details.
# Lend Documentation
Source: https://docs.optimism.io/app-developers/reference/actions/lend-documentation
API reference for Actions SDK lending operations, functions, and parameters.
## WalletLendNamespace
Wallet Lend Namespace
### Methods
| Function | Description |
| - | - |
| **[supportedChainIds()](#supportedchainids)** | Union of chain IDs supported by any configured provider. |
| **[getMarkets()](#getmarkets)** | Get all markets across all configured providers |
| **[getMarket()](#getmarket)** | Get a specific market by routing to the correct provider |
| **[getPositions()](#getpositions)** | |
| **[openPosition()](#openposition)** | Open a lending position |
| **[getPosition()](#getposition)** | Get position information for this wallet |
| **[closePosition()](#closeposition)** | Close a lending position (withdraw from market) |
#### `supportedChainIds()`
Union of chain IDs supported by any configured provider.
<sub>[<Icon icon="github" /> Source ↗](https://github.com/ethereum-optimism/actions/blob/@eth-optimism/actions-sdk@0.8.1/packages/sdk/프로젝트로 돌아가기