bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 11쪽
tifier for the
UserOperation
Returns
A Promise that resolves to
UserOperationReceipt
after the user operation is executed.
_
10
UserOperationReceipt = {
_
10
userOpHash: string
_
10
sender: string
_
10
nonce: string
_
10
actualGasUsed: string
_
10
actualGasCost: string
_
10
success: boolean
_
10
logs: Log[]
_
10
receipt: Receipt
_
10
}
Caveats
Use this method to obtain the full execution trace and status.
You can use this method to check if the
UserOperation
was successful by calling it repeatedly until the receipt is available.
getSupportedEntryPoints()
Retrieve all supported entry points.
Returns
A promise that resolves to an array of entry point addresses (strings) supported by the bundler.
Caveats
We use this method to obtain the default entry point if not provided in the
init()
method.
getChainId()
Retrieve the EIP-155 Chain ID.
Returns
A promise that resolves to the EIP-155 Chain ID string.
Migrate to V4
Safe React Hooks
Was this page helpful?
Report issue
## /sdk/react-hooks
SDK
Safe React Hooks
Safe React Hooks
The Safe React Hooks are the starting point for interacting with the Safe smart account using a React application.
These hooks are built on top of the
Starter Kit
, which leverages and abstracts the complex logic from several kits from the Safe{Core} SDK, allowing you to set a React context that gives access to the exposed Safe functionality everywhere in your application.
@safe-global/safe-react-hooks
The following guides show how to use the Safe React Hooks and integrate it into your project:
Send transactions
Resources
Safe React Hooks on GitHub
(opens in a new tab)
Safe4337Pack
Send Transactions
Was this page helpful?
Report issue
## /sdk/react-hooks/guides/send-transactions
SDK
Safe React Hooks
Guides
Send Transactions
Send Transactions
This guide will teach you how to deploy new Safe accounts and create, sign, and execute Safe transactions using the Safe React Hooks.
For more detailed information, see the
Safe React Hooks Reference
.
Prerequisites
Node.js and npm
(opens in a new tab)
Install dependencies
First, you need to install some dependencies.
_
10
pnpm add @safe-global/safe-react-hooks
Steps
Imports
Here are all the necessary imports for this guide.
_
10
import {
_
10
SafeProvider,
_
10
createConfig,
_
10
useSafe,
_
10
useSendTransaction,
_
10
SendTransactionVariables,
_
10
useConfirmTransaction,
_
10
ConfirmTransactionVariables
_
10
} from '@safe-global/safe-react-hooks'
_
10
import { sepolia } from 'viem/chains'
Create a signer and provider
Firstly, you need to get a signer, which will be the owner of a Safe account after it's deployed.
This example uses a private key, but any way to get an EIP-1193 compatible signer can be used.
_
10
const SIGNER_ADDRESS = // ...
_
10
const SIGNER_PRIVATE_KEY = // ...
_
10
_
10
const RPC_URL = 'https://rpc.ankr.com/eth_sepolia'
Initialize the Safe React Hooks
You need to wrap your app with the
SafeProvider
to have access to the different Safe React Hooks like
useSendTransaction()
,
useConfirmTransaction()
, and
usePendingTransactions()
that will provide the functionality you need in this guide.
SafeProvider
receives a
config
object with different properties to create the global configuration that you can get from the
createConfig
function.
New Safe account
Existing Safe account
When deploying a new Safe account for the connected signer, you need to pass the configuration of the Safe in the
safeOptions
property. In this case, the Safe account is configured with your signer as the only owner.
_
10
const config = createConfig({
_
10
chain: sepolia,
_
10
provider: RPC_URL,
_
10
signer: SIGNER_PRIVATE_KEY,
_
10
safeOptions: {
_
10
owners: [SIGNER_ADDRESS],
_
10
threshold: 1
_
10
}
_
10
})
To apply the global configuration to your app, pass the created
config
to the
SafeProvider
.
_
10
<SafeProvider config={config}>
_
10
<App />
_
10
</SafeProvider>
Create a Safe transaction
Create an array of Safe transactions to execute.
_
10
const transactions = [{
_
10
to: '0x...',
_
10
data: '0x',
_
10
value: '0'
_
10
}]
Send the Safe transaction
Create a
SendTransaction
component in your application to create and send a transaction.
If you configured your Safe with
threshold
equal to
1
, calling the
sendTransaction
function from the
useSendTransaction
hook will execute the Safe transaction. However, if the
threshold
is greater than
1
the other owners of the Safe will need to confirm the transaction until the required number of signatures are collected.
SendTransaction.tsx
_
15
function SendTransaction() {
_
15
const { sendTransaction } = useSendTransaction()
_
15
_
15
const sendTransactionParams: SendTransactionVariables = {
_
15
transactions
_
15
}
_
15
_
15
return (
_
15
<button onClick={() => sendTransaction(sendTransactionParams)}>
_
15
Send Transaction
_
15
</button>
_
15
)
_
15
}
_
15
_
15
export default SendTransaction
Confirm the Safe transaction
Create a
ConfirmPendingTransactions
component in your application to check the transactions pending for confirmation in case the Safe transaction needs to be confirmed by other Safe owners.
Retrieve all the pending Safe transactions from the Safe Transaction Service by calling the
getPendingTransaction
function from the
useSafe
hook, and call the
confirmTransaction
function from the
useConfirmTransaction
hook to confirm them.
Notice that the
SafeProvider
configuration needs to be initialized with a different Safe owner as the
signer
when confirming a transaction.
ConfirmPendingTransactions.tsx
_
20
function ConfirmPendingTransactions() {
_
20
const { getPendingTransactions } = useSafe()
_
20
const { data = [] } = getPendingTransactions()
_
20
const { confirmTransaction } = useConfirmTransaction()
_
20
_
20
return (
_
20
<>
_
20
{data.length > 0 && data.map(tx => (
_
20
<>
_
20
{tx.safeTxHash}
_
20
<button onClick={() => confirmTransaction({
_
20
safeTxHash: tx.safeTxHash
_
20
})} />
_
20
</>
_
20
))}
_
20
</>
_
20
)
_
20
}
_
20
_
20
export default ConfirmPendingTransactions
Once the total number of confirmations reaches the
threshold
of the Safe, the
confirmTransaction
will automatically execute the transaction.
Recap and further reading
After following this guide, you are able to deploy new Safe accounts and create, sign, and execute Safe transactions using the Safe React Hooks.
Safe React Hooks
Reference
Was this page helpful?
Report issue
## /reference-sdk-react-hooks/overview
React Hooks Reference
Overview
Safe React Hooks Reference
Safe React Hooks
is a collection of React hooks written in TypeScript that simplify the usage of the Safe{Core} SDK for React developers.
Install dependencies
To add the Safe React Hooks to your project, run:
pnpm
npm
yarn
_
10
pnpm add @safe-global/safe-react-hooks
← Go Back
SafeProvider
Was this page helpful?
Report issue
## /sdk/signers
SDK
Signers
Signers
Safe Smart Accounts can be set up with multiple and different signer accounts.
The following guides show how to create a signer account with different service providers and use them to initialize any of the kits from the Safe{Core} SDK.
Dynamic
Magic
Passkeys
Privy
Web3Auth
Resources
Demo app on GitHub
(opens in a new tab)
Reference
Dynamic
Was this page helpful?
Report issue
## /sdk/signers/dynamic
SDK
Signers
Dynamic
Dynamic Signer
In this guide, you will learn how to create a
Dynamic
(opens in a new tab)
signer that can be added as a Safe owner and used to initialize any of the kits from the Safe{Core} SDK.
Check out the
Safe Signers demo app
(opens in a new tab)
on GitHub to follow along this guide with the completed code.
Note that this guide will focus on supporting Ethereum and EVM-compatible wallets. You can enable, import and add
more connectors
(opens in a new tab)
as needed.
Prerequisites
A
Dynamic account
(opens in a new tab)
and an environment ID.
Install dependencies
npm
yarn
pnpm
_
10
npm install @dynamic-labs/sdk-react-core @dynamic-labs/ethereum
Steps
Imports
Here are the necessary imports for this guide.
_
10
import {
_
10
DynamicContextProvider,
_
10
useDynamicContext,
_
10
useIsLoggedIn
_
10
} from '@dynamic-labs/sdk-react-core'
_
10
import {
_
10
EthereumWalletConnectors,
_
10
isEthereumWallet
_
10
} from '@dynamic-labs/ethereum'
Get the Environment ID
Once you create a new Dynamic project in
the dashboard
(opens in a new tab)
, you will find your environment ID in
the SDK & API Keys page
(opens in a new tab)
.
Once you have it, you need to initialize the
DYNAMIC_ENVIRONMENT_ID
variable with it.
_
10
const DYNAMIC_ENVIRONMENT_ID = // ...
Initialize Dynamic
Dynamic works with React hooks. This means you can wrap your app with the
DynamicContextProvider
and have access to several react hooks like
useDynamicContext()
that will provide all the functionality.
DynamicContextProvider
receives an
environmentId
and other configuration options. Check
Dynamic React SDK documentation
(opens in a new tab)
to learn more about all the different configuration options.
_
10
<DynamicContextProvider
_
10
settings={{
_
10
environmentId: DYNAMIC_ENVIRONMENT_ID,
_
10
walletConnectors: [EthereumWalletConnectors],
_
10
// Add other configuration options as needed
_
10
}}
_
10
>
_
10
<App />
_
10
</DynamicContextProvider>
In this guide you will use the
primaryWallet
from the
useDynamicContext()
hook, and the
useIsLoggedIn()
hook.
_
10
const { primaryWallet } = useDynamicContext()
_
10
const isLoggedIn = useIsLoggedIn()
Login
In the
App
component, add
the DynamicWidget component
(opens in a new tab)
that will handle all the login and authentication logic for you.
_
10
import { DynamicWidget } from '@dynamic-labs/sdk-react-core'
_
10
_
10
const App = () => {
_
10
return (
_
10
<>
_
10
// Your other content here
_
10
<DynamicWidget />
_
10
</>
_
10
)
_
10
}
Get the provider and signer
Once the user is logged in through the
DynamicWidget
, you can get the
provider
and
signer
, which is the externally-owned account of the user that was derived from its credentials.
To do that there is a
useEffect()
that executes when any of the
isLoggedIn
and
primaryWallet
variables have their values updated. Once they are all
true
, you have access to the user's connected signer. Note that you should also check that the wallet is an Ethereum wallet using the
isEthereumWallet()
function.
You can instantiate the provider and signer like so:
_
10
useEffect(() => {
_
10
const init = async () => {
_
10
if (isLoggedIn && primaryWallet && isEthereumWallet(primaryWallet)) {
_
10
const provider = await primaryWallet.getWalletClient()
_
10
_
10
const signer = primaryWallet.address
_
10
}
_
10
}
_
10
init()
_
10
}, [isLoggedIn, primaryWallet])
With the
provider
and
signer
you are ready to instantiate any of the kits from the Safe{Core} SDK and set up or use this signer as a Safe owner.
Recap and further reading
After following this guide, you are able to create a Safe signer using Dynamic and get the
provider
and
signer
required to initialize the kits from the Safe{Core} SDK.
Learn more about Dynamic by checking the following resources:
Dynamic website
(opens in a new tab)
Dynamic documentation
(opens in a new tab)
Dynamic quickstart guide
(opens in a new tab)
Dynamic in a Safe App
(opens in a new tab)
Signers
Magic
Was this page helpful?
Report issue
## /sdk/signers/magic
SDK
Signers
Magic
Magic Signer
In this guide, you will learn how to create a
Magic
(opens in a new tab)
signer that can be added as a Safe owner and used to initialize any of the kits from the Safe{Core} SDK.
Check out the
Safe Signers demo app
(opens in a new tab)
on GitHub to follow along this guide with the completed code.
Prerequisites
Node.js and npm
(opens in a new tab)
.
A
Magic account
(opens in a new tab)
and an API key.
Install dependencies
npm
yarn
pnpm
_
10
npm install magic-sdk
Steps
Imports
Here are the necessary imports for this guide.
_
10
import { Magic } from 'magic-sdk'
In addition, you will need to import a web3 library of your choice to use in the "Get the provider and signer" section. In this guide, we are using
viem
.
Get the API Key
Check Magic documentation on how to create a new project in their
dashboard
(opens in a new tab)
and
get the API key.
(opens in a new tab)
Once you have it, you need to initialize the
MAGIC_API_KEY
variable with it.
_
10
const MAGIC_API_KEY = // ...
Initialize Magic
Magic initialization is done by instantiating the
Magic
class with an
MAGIC_API_KEY
. Optionally, it also accepts some configuration parameters that can be checked in the
Magic Web API Reference
(opens in a new tab)
.
_
10
const magic = new Magic(MAGIC_API_KEY)
Login
To login with an email address or social account you need to call the following method, that will open the popup and request the user to submit the login form.
_
10
await magic.wallet.connectWithUI()
Get the provider and signer
Once the user is logged in, you can get the
provider
and
signer
, which is the externally-owned account of the user that was derived from its credentials.
viem
You can instantiate the provider using
viem
and the following imports:
_
10
import { createWalletClient, custom } from 'viem'
_
10
import { sepolia } from 'viem/chains'
_
10
const provider = createWalletClient({
_
10
chain: sepolia,
_
10
transport: custom(magic.rpcProvider)
_
10
})
_
10
_
10
const metadata = await magic.user.getInfo()
_
10
const signer = metadata.publicAddress
With the
provider
and
signer
you are ready to instantiate any of the kits from the Safe{Core} SDK and set up or use this signer as a Safe owner.
Logout
Finally, to logout the user, call the
logout()
method.
_
10
await magic.user.logout()
Recap and further reading
After following this guide, you are able to create a Safe signer using Magic and get the
provider
and
signer
required to initialize the kits from the Safe{Core} SDK.
Learn more about Magic by checking the following resources:
Magic website
(opens in a new tab)
Magic documentation
(opens in a new tab)
Magic quickstart guide
(opens in a new tab)
Dynamic
Passkeys
Was this page helpful?
Report issue
## /sdk/signers/passkeys
SDK
Signers
Passkeys
Passkeys Signer
In this guide, you will learn how to create a Passkey signer that can be added as a Safe owner and used to initialize any of the kits from the Safe{Core} SDK.
⚠️
Please always use a combination of passkeys and other authentication methods to ensure the security of your users' assets.
Prerequisites
Node.js and npm
(opens in a new tab)
.
Passkeys feature is available only in
secure contexts
(opens in a new tab)
(HTTPS), in some or all
supporting browsers
(opens in a new tab)
.
Install dependencies
npm
yarn
pnpm
_
10
npm install @safe-global/protocol-kit
Steps
Imports
Here are the necessary imports for this guide.
_
10
import Safe from '@safe-global/protocol-kit'
In addition, you will need to import a web3 library of your choice to use in the "Get the provider and signer" section. In this guide, we are using
viem
.
Create a passkey
Firstly, you need to generate a passkey credential using the
WebAuthn API
(opens in a new tab)
in a supporting browser environment.
_
25
const RP_NAME = 'Safe Smart Account'
_
25
const USER_DISPLAY_NAME = 'User display name'
_
25
const USER_NAME = 'User name'
_
25
_
25
const passkeyCredential = await navigator.credentials.create({
_
25
publicKey: {
_
25
pubKeyCredParams: [
_
25
{
_
25
alg: -7,
_
25
type: 'public-key'
_
25
}
_
25
],
_
25
challenge: crypto.getRandomValues(new Uint8Array(32)),
_
25
rp: {
_
25
name: RP_NAME
_
25
},
_
25
user: {
_
25
displayName: USER_DISPLAY_NAME,
_
25
id: crypto.getRandomValues(new Uint8Array(32)),
_
25
name: USER_NAME
_
25
},
_
25
timeout: 60_000,
_
25
attestation: 'none'
_
25
}
_
25
})
After generating the
passkeyCredential
object, you need to create the signer. This signer will be a
PasskeyArgType
object containing the
rawId
and the
coordinates
information.
_
10
if (!passkeyCredential) {
_
10
throw Error('Passkey creation failed: No credential was returned.')
_
10
}
_
10
_
10
const passkeySigner = await Safe.createPasskeySigner(passkeyCredential)
At this point, it's critical to securely store the information in the
passkeySigner
object in a persistent service. Losing access to this data will result in the user being unable to access their passkey and, therefore, their Safe Smart Account.
Get the provider and signer
Once the passkey is created, you need the
provider
and
signer
properties required to instantiate the Safe{Core} SDK kits.
Check
how to initialize the Protocol Kit
viem
You can instantiate the provider using
viem
and the following imports:
_
10
import { createWalletClient, http } from 'viem'
_
10
import { sepolia } from 'viem/chains
_
10
_
10
const provider = createWalletClient({
_
10
chain: sepolia,
_
10
transport: http('https://rpc.ankr.com/eth_sepolia')
_
10
})
_
10
const signer = passkey
Instantiate SDK
With the
provider
and
signer
you are ready to instantiate any of the kits from the Safe{Core} SDK and set up or use this signer as a Safe owner.
For example, you can instantiate the
protocol-kit
as follows and sign a transaction with the passkey signer:
_
10
const protocolKit = await Safe.init({ provider, signer, safeAddress })
_
10
_
10
const transaction = { to: '0x1234', value: '0x0', data: '0x' }
_
10
const safeTransaction = await protocolKit.createTransaction({ transactions: [transaction] })
_
10
const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction)
Recap and further reading
After following this guide, you are able to create a Safe signer using passkeys and get the
provider
and
signer
required to initialize the kits from the Safe{Core} SDK.
Safe Passkeys contracts
(opens in a new tab)
Magic
Privy
Was this page helpful?
Report issue
## /sdk/signers/privy
SDK
Signers
Privy
Privy Signer
In this guide, you will learn how to create a
Privy
(opens in a new tab)
signer that can be added as a Safe owner and used to initialize any of the kits from the Safe{Core} SDK.
Check out the
Safe Signers demo app
(opens in a new tab)
on GitHub to follow along this guide with the completed code.
Prerequisites
Node.js and npm
(opens in a new tab)
.
A
Privy account
(opens in a new tab)
and an App ID.
Install dependencies
npm
yarn
pnpm
_
10
npm install @privy-io/react-auth
Steps
Imports
Here are the necessary imports for this guide.
_
10
import { PrivyProvider, usePrivy, useWallets } from '@privy-io/react-auth'
In addition, you will need to import a web3 library of your choice to use in the "Get the provider and signer" section. In this guide, we are using
viem
.
Get the App ID
Check Privy documentation on how to create a new project in their
dashboard
(opens in a new tab)
and
get the client ID
(opens in a new tab)
.
Once you have it, you need to initialize the
PRIVY_APP_ID
variable with it.
_
10
const PRIVY_APP_ID = // ...
Initialize Privy
Privy works with React hooks. This means you can wrap your app with the
PrivyProvider
and have access to several react hooks like
usePrivy()
and
useWallets()
that will provide all the functionality.
ProvyProvider
receives an
appId
and a
config
object with different properties. Check
Using the Privy React SDK
(opens in a new tab)
from Privy documentation to learn more about all the different configuration options, appearance, login methods, etc.
_
10
<PrivyProvider
_
10
appId={PRIVY_APP_ID}
_
10
config={{
_
10
embeddedWallets: {
_
10
createOnLogin: 'users-without-wallets' // defaults to 'off'
_
10
}
_
10
}}
_
10
>
_
10
<App />
_
10
</PrivyProvider>
In this guide you will use the following variables and methods from the
usePrivy()
and
useWallets()
React hooks.
_
10
const { login, logout,프로젝트로 돌아가기