### Install Dependencies Source: https://docs.safe.global/advanced/erc-4337/guides/permissionless-quickstart Install the viem and permissionless libraries required for the quickstart guide. ```bash pnpm install viem permissionless ``` -------------------------------- ### Interface and Example Contract for Safe Setup Source: https://docs.safe.global/reference-smart-account/setup/setup Defines the `ISafe` interface with the `setup` function and provides an `Example` contract demonstrating its usage. This is used to illustrate how to call the setup function with various parameters. ```solidity interface ISafe { function setup( address[] _owners, uint256 _threshold, address to, bytes data, address fallbackHandler, address paymentToken, uint256 payment, address payable paymentReceiver ) external; } contract Example { function example() ... { (ISafe safe).setup( [0x..., 0x...], 1, 0x..., "0x...", 0x..., 0x..., 0, 0x... ); } } ``` -------------------------------- ### Setup Project Dependencies Source: https://docs.safe.global/advanced/smart-account-migration Install necessary packages for Safe Smart Account migration. ```bash mkdir safe-migration-tutorial && cd safe-migration-tutorial npm init -y npm install @safe-global/protocol-kit @safe-global/types-kit viem ``` -------------------------------- ### Install and Start AASA Server Source: https://docs.safe.global/advanced/passkeys/tutorials/react-native Install dependencies and start the Node Express AASA server. This server is required for testing passkey functionality. ```bash cd aasa-server npm install npm start ``` -------------------------------- ### Get Messages with Offset Source: https://docs.safe.global/reference-sdk-api-kit/getmessages Retrieves messages for a Safe address starting from a specific index. This example demonstrates the use of the 'offset' parameter for pagination. ```typescript const messagesResponse = await apiKit.getMessages( '0x...', { offset: 50 } ) ``` -------------------------------- ### Get Safe Address from Deployment Transaction Receipt Source: https://docs.safe.global/reference-sdk-protocol-kit/deployment/getsafeaddressfromdeploymenttx This example demonstrates how to use `getSafeAddressFromDeploymentTx` with a transaction receipt and a specified Safe version. Ensure you have the necessary viem setup and Protocol Kit imported. ```typescript import { getSafeAddressFromDeploymentTx } from '@safe-global/protocol-kit' import { createWalletClient, http } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { sepolia } from 'viem/chains' import { waitForTransactionReceipt } from 'viem/actions' import { protocolKit } from './setup.ts' const account = privateKeyToAccount('0x...') const client = createWalletClient({ account, chain: sepolia, transport: http('https://rpc.ankr.com/eth_sepolia') }) const transactionReceipt = await waitForTransactionReceipt(client, { hash: '0x...' }) const safeAddress = getSafeAddressFromDeploymentTx( transactionReceipt, safeVersion: '1.4.1' ) ``` -------------------------------- ### Initialize Project Directory and npm Source: https://docs.safe.global/advanced/smart-account-modules/smart-account-modules-tutorial Create a new project directory and initialize npm. This is the first step in setting up your project. ```bash 1 mkdir safe-module-tutorial && cd safe-module-tutorial 2 npm init -y ``` -------------------------------- ### Install Starter Kit with npm Source: https://docs.safe.global/reference-sdk-starter-kit/overview Add the Safe SDK Starter Kit to your project using npm. ```bash npm install @safe-global/sdk-starter-kit ``` -------------------------------- ### Get Transfer Request Example Source: https://docs.safe.global/core-api/transaction-service-reference/katana Example of how to make a GET request to retrieve a specific token transfer using its ID. ```curl curl -X GET https://api.safe.global/tx-service/katana/api/v1/transfer/3b3b57b3 \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Install Starter Kit with pnpm Source: https://docs.safe.global/reference-sdk-starter-kit/overview Add the Safe SDK Starter Kit to your project using pnpm. ```bash pnpm add @safe-global/sdk-starter-kit ``` -------------------------------- ### Initialize Project Directory Source: https://docs.safe.global/advanced/smart-account-guards/smart-account-guard-tutorial Create a new project directory and initialize npm. This is the first step in setting up the project environment. ```bash mkdir safe-guard-tutorial && cd safe-guard-tutorial npm init -y ``` -------------------------------- ### Install Starter Kit with yarn Source: https://docs.safe.global/reference-sdk-starter-kit/overview Add the Safe SDK Starter Kit to your project using yarn. ```bash yarn add @safe-global/sdk-starter-kit ``` -------------------------------- ### GET User Operations Request Example Source: https://docs.safe.global/core-api/transaction-service-reference/monad-testnet Example of how to make a GET request to retrieve user operations for a given Safe address on Monad Testnet. Includes necessary headers for API interaction. ```curl curl -X GET https://api.safe.global/tx-service/monad-testnet/api/v1/safes/0xcd2E72aEBe2A203b84f46DEEC948E6465dB51c75/user-operations/ \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Install Dependencies Source: https://docs.safe.global/sdk/protocol-kit/guides/safe-deployment Install the necessary Protocol Kit and Viem dependencies for Safe deployment. ```bash pnpm add @safe-global/protocol-kit viem ``` -------------------------------- ### GET /safes/{address}/user-operations/ - Request Example Source: https://docs.safe.global/core-api/transaction-service-reference/chiado Example of how to make a GET request to retrieve user operations for a specific Safe address. Includes necessary headers for authentication and content type. ```curl curl -X GET https://api.safe.global/tx-service/chi/api/v1/safes/0xcd2E72aEBe2A203b84f46DEEC948E6465dB51c75/user-operations/ \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Get Transfer Sample Request Source: https://docs.safe.global/core-api/transaction-service-reference/monad Example of how to make a GET request to retrieve a specific transfer by its ID. ```bash curl -X GET https://api.safe.global/tx-service/monad/api/v1/transfer/3b3b57b3 \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Install Dependencies Source: https://docs.safe.global/advanced/erc-7579/tutorials/7579-tutorial Install Permissionless.js, Viem, and truncate-eth-address for smart account functionality and address formatting. ```bash pnpm add permissionless@0.2.0 viem@2.21.7 truncate-eth-address@1.0.2 ``` -------------------------------- ### Get Transfer Sample Request Source: https://docs.safe.global/core-api/transaction-service-reference/base Example of how to make a GET request to retrieve a specific transfer ID from the transaction service. ```curl curl -X GET https://api.safe.global/tx-service/base/api/v1/transfer/3b3b57b3 \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Full Passkey Signer Setup with ProtocolKit v7 Source: https://docs.safe.global/sdk/protocol-kit/guides/migrate-to-v7 This snippet demonstrates the complete process of setting up a passkey signer, from creating a WebAuthn credential to initializing ProtocolKit. ```typescript import Safe, { getP256VerifierAddress, type PasskeyArgType } from '@safe-global/protocol-kit' // 1. Create a WebAuthn credential (for example, via navigator.credentials.create) const credential = await navigator.credentials.create({ publicKey: { ... } }) // 2. Extract the passkey data from the credential const extracted = await Safe.createPasskeySigner(credential) // 3. Get the recommended verifier address for your chain const verifierAddress = getP256VerifierAddress(chainId) // 4. Build the full PasskeyArgType const passkeySigner: PasskeyArgType = { ...extracted, verifierAddress } // 5. Use it to initialize a Safe const protocolKit = await Safe.init({ provider, signer: passkeySigner, safeAddress: '0x...' }) ``` -------------------------------- ### Get Transfer Sample Request Source: https://docs.safe.global/core-api/transaction-service-reference/base-sepolia Example of how to make a GET request to retrieve a specific token transfer using its ID. ```bash curl -X GET https://api.safe.global/tx-service/basesep/api/v1/transfer/3b3b57b3 \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Get Transfer Sample Request Source: https://docs.safe.global/core-api/transaction-service-reference/codex Example of how to make a GET request to retrieve a specific transfer by its ID. Ensure to include the 'Accept' and 'Authorization' headers. ```bash curl -X GET https://api.safe.global/tx-service/codex/api/v1/transfer/3b3b57b3 \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Install Project Dependencies Source: https://docs.safe.global/advanced/passkeys/tutorials/react Installs the Safe{Core} SDK (Relay Kit and Protocol Kit), viem, Material UI, and SVGR for the project. Also adds the .env.local file with the Pimlico API key. ```bash pnpm add @safe-global/protocol-kit@4.1.0 @safe-global/relay-kit@3.1.0 viem @emotion/react @emotion/styled @mui/material @mui/icons-material @svgr/webpack ``` ```bash echo "NEXT_PUBLIC_PIMLICO_API_KEY='your_pimlico_api_key_goes_here'" > .env.local ``` -------------------------------- ### Create components directory and LoginWithPasskey.tsx file Source: https://docs.safe.global/home/passkeys-tutorials/safe-passkeys-tutorial Sets up the necessary directory and file for the passkey login component. ```bash 1 cd .. 2 mkdir components 3 cd components 4 touch LoginWithPasskey.tsx ``` -------------------------------- ### Get Owners Who Approved Transaction (Direct Hash) Source: https://docs.safe.global/reference-sdk-protocol-kit/safe-info/getownerswhoapprovedtx This example shows how to directly pass the Safe transaction hash string to the `getOwnersWhoApprovedTx` function to get the list of approving owners. ```typescript const ownerAddresses = await protocolKit.getOwnersWhoApprovedTx( '0x...' ) ``` -------------------------------- ### Get Transfer Sample Request Source: https://docs.safe.global/core-api/transaction-service-reference/bsc Example of how to make a GET request to retrieve a specific token transfer using its ID. Ensure to replace 'YOUR_API_KEY' with your actual API key. ```curl curl -X GET https://api.safe.global/tx-service/bnb/api/v1/transfer/3b3b57b3 \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Create lib Folder Source: https://docs.safe.global/advanced/passkeys/tutorials/react-native Create a 'lib' folder at the project root to store custom logic. ```bash mkdir lib cd lib ``` -------------------------------- ### Get Multisig Transaction Request Example Source: https://docs.safe.global/core-api/transaction-service-reference/celo-sepolia Example of a cURL request to retrieve a multisignature transaction using its Safe transaction hash. Replace YOUR_API_KEY with your valid API key. ```curl curl -X GET https://api.safe.global/tx-service/celo-sep/api/v2/multisig-transactions/0xa059b4571d8e6cf551eea796f9d86a414083bdc3d5d5be88486589a7b6214be2/ \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Create Layout Files Source: https://docs.safe.global/advanced/passkeys/tutorials/nuxt Commands to create the necessary layout directory and default.vue file for styling. ```bash mkdir ../layouts cd ../layouts touch default.vue ``` -------------------------------- ### Install Protocol Kit Source: https://docs.safe.global/sdk/signers/passkeys Install the Protocol Kit package using npm, yarn, or pnpm. ```bash npm install @safe-global/protocol-kit ``` -------------------------------- ### Create and Navigate to Project Directory Source: https://docs.safe.global/home/ai-agent-setup Create a new directory for your AI agent project and navigate into it. ```bash mkdir my-safe-agent cd my-safe-agent ``` -------------------------------- ### Get Transfer Sample Response Source: https://docs.safe.global/core-api/transaction-service-reference/base-sepolia Example JSON response for a successful retrieval of an ETHER_TRANSFER. ```json { "type": "ETHER_TRANSFER", "executionDate": "2024-07-24T20:54:48Z", "blockNumber": 6369595, "transactionHash": "0x4c8bc3a9f32eed6b4cb8225d6884e9c7006d6740b0a6896cee7b254aa037920e", "to": "0x3A16E3090e32DDeD2250E862B9d5610BEF13e93d", "value": "10000000000", "tokenId": null, "tokenAddress": null, "transferId": "i4c8bc3a9f32eed6b4cb8225d6884e9c7006d6740b0a6896cee7b254aa037920e0,0,0", "tokenInfo": null, "from": "0x5298A93734C3D979eF1f23F78eBB871879A21F22" } ``` -------------------------------- ### Install Dependencies Source: https://docs.safe.global/sdk/signers/web3auth Install the necessary Web3Auth packages using npm, yarn, or pnpm. ```bash npm install @web3auth/modal @web3auth/base @web3auth/ethereum-provider ``` -------------------------------- ### Get Service Information Source: https://docs.safe.global/reference-sdk-api-kit/getserviceinfo Retrieves the information and configuration of the service using the apiKit. Requires setup from './setup.ts'. ```typescript import { apiKit } from './setup.ts' const serviceInfo = await apiKit.getServiceInfo() ``` -------------------------------- ### Import and Get Message Source: https://docs.safe.global/reference-sdk-api-kit/getmessage Demonstrates how to import the apiKit from setup and use the getMessage function with a message hash. ```typescript import { apiKit } from './setup.ts' const messageHash = '0x...' const message = await apiKit.getMessage(messageHash) ``` -------------------------------- ### init(safe4337InitOptions) Source: https://docs.safe.global/sdk/relay-kit/reference/safe-4337-pack Initializes the Safe 4337 Pack. This method is used to create the initial instance of the pack, providing configurations for the provider, signer, RPC URLs, bundler, custom contracts, Safe account options, and paymaster options. ```APIDOC ## init(safe4337InitOptions) ### Description Initializes the Safe 4337 Pack. This method is used to create the initial instance of the pack, providing configurations for the provider, signer, RPC URLs, bundler, custom contracts, Safe account options, and paymaster options. ### Parameters #### `safe4337InitOptions` Object - **`provider`** (EIP-1193 compatible provider or RPC URL) - Required - The EIP-1193 compatible provider or RPC URL of the selected chain. - **`signer`** (Passkey or private key) - Optional - A passkey or the signer private key if the `provider` doesn't resolve to a signer account. If the `provider` resolves to multiple signer addresses, the `signer` property can be used to specify which account to connect, otherwise the first address returned will be used. - **`rpcUrl`** (string) - Required - The RPC URL of the selected chain. - **`bundlerUrl`** (string) - Required - The bundler's URL. - **`safeModulesVersion`** (string) - Optional - The version of the Safe Modules contract. - **`customContracts`** (object) - Optional - An object with custom contract addresses. - **`entryPointAddress`** (string) - Optional - The address of the entry point. Defaults to the address returned by the `eth_supportedEntryPoints` method from the provider API. - **`safe4337ModuleAddress`** (string) - Optional - The address of the `Safe4337Module`. Defaults to `safe-modules-deployments` using the current version. - **`addModulesLibAddress`** (string) - Optional - The address of the `AddModulesLib` library. Defaults to `safe-modules-deployments` using the current version. - **`options`** (object) - Optional - The Safe account options. - **`safeAddress`** (string) - Optional - The Safe address. You can only use this prop to specify an existing Safe account. - **`owners`** (array of strings) - Optional - The array with Safe owners. - **`threshold`** (number) - Optional - The Safe threshold. This is the number of owners required to sign and execute a transaction. - **`safeVersion`** (string) - Optional - The version of the Safe contract. Defaults to the current version. - **`saltNonce`** (number) - Optional - The Safe salt nonce. Changing this value enables the creation of different safe (predicted) addresses using the same configuration (`owners`, `threshold`, and `safeVersion`). - **`paymasterOptions`** (object) - Optional - The paymaster options. - **`paymasterUrl`** (string) - Optional - The paymaster URL. You can obtain the URL from the management dashboard of the selected services provider. This URL will be used for gas estimations. - **`isSponsored`** (boolean) - Optional - A boolean flag to indicate if we want to use a paymaster to sponsor transactions. - **`sponsorshipPolicyId`** (string) - Optional - The sponsorship policy ID can be obtained from the management dashboard of the selected payment services provider. - **`paymasterAddress`** (string) - Optional - The address of the paymaster contract to use. - **`paymasterTokenAddress`** (string) - Optional - The paymaster token address for transaction fee payments. - **`amountToApprove`** (number) - Optional - The `paymasterTokenAddress` amount to approve. ### Returns A promise that resolves to an instance of the `Safe4337Pack`. ### Caveats - Use this method to create the initial instance instead of the standard constructor. - You should search for some API services URLs and contract addresses in the management dashboards of your selected provider. These include `bundlerUrl`, `paymasterUrl`, `paymasterAddress`, `paymasterTokenAddress`, `sponsorshipPolicyId`, and `rpcUrl` (In this case any valid RPC should be fine). - The SDK uses default versions when `safeModulesVersion` or `safeVersion` are not specified. You can find more details about the current versions here. - The `saltNonce` derives different Safe addresses by using the `protocol-kit` method `predictSafeAddress`. You can find more details about this process here. - We typically initialize the pack in two ways. One way is by using an existing account with the `safeAddress` prop. The other way is by using the `owners`, `threshold`, `saltNonce`, and `safeVersion` props to create a new Safe account. You can also apply the second method to existing addresses, as the output address will be the same if the inputs are identical. - The SDK queries `eth_supportedEntryPoints` for a default `entryPointAddress` if not given. It fetches `safe4337ModuleAddress` and `addModulesLibAddress` from the `safe-modules-deployments` repository if not provided. You can find them at: safe-modules-deployments. - To use a paymaster without sponsorship, you need to hold a certain amount of `paymasterTokenAddress` in the Safe account for fees. Make sure to provide the `paymasterAddress` as well. - You can choose to use a paymaster to sponsor transactions by setting the `isSponsored` prop. When sponsoring transactions, you need to provide the `paymasterUrl`, `paymasterAddress`, and optionally the `sponsorshipPolicyId`. - An approval for the concrete ERC-20 token is required to use the paymaster so remember to add the `paymasterTokenAddress` of the ERC-20 token that will pay the fees. The SDK will encode this approval internally and send it to the bundler with the rest of the user operation. - Specify the amount to approve for the `paymasterTokenAddress` using the `amountToApprove` prop. This is necessary when the Safe account is not deployed, and you need to approve the paymaster token for fee payments and Safe account setup. ``` -------------------------------- ### GET /safes/{address}/user-operations/ Request Example Source: https://docs.safe.global/core-api/transaction-service-reference/mantle-sepolia Example of a cURL request to retrieve user operations for a specific Safe address on the Mantle Sepolia network. Includes necessary headers for authentication and content type. ```curl curl -X GET https://api.safe.global/tx-service/mnt-sep/api/v1/safes/0xcd2E72aEBe2A203b84f46DEEC948E6465dB51c75/user-operations/ \ -H "Accept: application/json" \ -H "content-type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ ``` -------------------------------- ### Install Protocol Kit Source: https://docs.safe.global/reference-sdk-protocol-kit/overview Add the Protocol Kit to your project using Yarn. ```bash yarn add @safe-global/protocol-kit ``` -------------------------------- ### Get Safe Operations with a Specific Offset Source: https://docs.safe.global/reference-sdk-api-kit/getsafeoperationsbyaddress Fetches Safe operations starting from a specified index, used for paginating through results. ```typescript const safeOperationsResponse = await apiKit.getSafeOperationsByAddress( { safeAddress: '0x...', offset: 50 } ) ``` -------------------------------- ### Install Dynamic SDK Dependencies Source: https://docs.safe.global/sdk/signers/dynamic Install the necessary packages for Dynamic integration with React and Ethereum. ```bash npm install @dynamic-labs/sdk-react-core @dynamic-labs/ethereum ``` -------------------------------- ### CreateConfig with Signer Parameter Source: https://docs.safe.global/reference-sdk-react-hooks/createconfig This example shows how to configure the `signer` parameter in `createConfig`. The signer is used for signing transactions and interacting with the Safe as an owner. ```javascript const config = createConfig({ chain: sepolia provider, signer, safeAddress: '0x...' }) ``` -------------------------------- ### On-chain Message Hashing Setup Source: https://docs.safe.global/sdk/protocol-kit/guides/signatures/messages Get the SignMessageLib contract instance for a specific Safe version to prepare for on-chain message storage. ```typescript const signMessageLibContract = await getSignMessageLibContract({ safeVersion: '1.4.1' }) ``` -------------------------------- ### Get Pending Safe Operations by Safe Address Source: https://docs.safe.global/reference-sdk-api-kit/getpendingsafeoperations A basic example of calling `getPendingSafeOperations` by providing only the `safeAddress`. The `options` parameter is optional. ```typescript const safeOperationsResponse = await apiKit.getPendingSafeOperations({ safeAddress: '0x...' }) ```