### Install SDK Starter Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/packages/sdk-starter-kit/README.md Install the @safe-global/sdk-starter-kit package using either yarn or npm. ```bash yarn add @safe-global/sdk-starter-kit ``` ```bash npm install @safe-global/sdk-starter-kit ``` -------------------------------- ### Install Protocol Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/packages/protocol-kit/README.md Install the Protocol Kit package using yarn or npm. ```bash yarn add @safe-global/protocol-kit npm install @safe-global/protocol-kit ``` -------------------------------- ### Setup Safe Account Owners using SDK Starter Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to set up Safe accounts with different owner configurations using the SDK Starter Kit. ```bash pnpm play owner-management ``` -------------------------------- ### Install Safe API Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/packages/api-kit/README.md Install the @safe-global/api-kit package using yarn or npm. ```bash yarn add @safe-global/api-kit npm install @safe-global/api-kit ``` -------------------------------- ### Install Dependencies and Build Project Source: https://github.com/safe-global/safe-core-sdk/blob/main/CONTRIBUTING.md Install all project dependencies and build the entire monorepo using pnpm. This command should be run from the project root. ```bash pnpm install pnpm build ``` -------------------------------- ### Install Safe Core SDK Dependencies Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Install the necessary packages for integrating the Safe Core SDK. These include types-kit, protocol-kit, and api-kit. ```bash npm install @safe-global/types-kit @safe-global/protocol-kit @safe-global/api-kit # or yarn add @safe-global/types-kit @safe-global/protocol-kit @safe-global/api-kit ``` -------------------------------- ### Initialize Protocol Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Initialize the Protocol Kit with provider, signer, and the Safe address. This is the basic setup for interacting with Safe contracts. ```javascript import Safe from '@safe-global/protocol-kit' const protocolKit = await Safe.init({ provider, signer, safeAddress }) ``` -------------------------------- ### Check Node and pnpm Versions Source: https://github.com/safe-global/safe-core-sdk/blob/main/CONTRIBUTING.md Verify your installed Node.js and pnpm versions. Ensure you are using the latest Node LTS and pnpm 10.16+. ```bash node -v pnpm -v ``` -------------------------------- ### Get Pending Transactions Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Retrieve a list of pending transactions for a given Safe address from the Safe Transaction Service. ```javascript const pendingTxs = await apiKit.getPendingTransactions(safeAddress) ``` -------------------------------- ### Get Specific Transaction by Hash Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Retrieve a specific transaction from the Safe Transaction Service using its Safe transaction hash. ```javascript const tx = await apiKit.getTransaction(safeTxHash) ``` -------------------------------- ### Get Next Nonce Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Retrieve the next available nonce for a Safe transaction to ensure uniqueness, especially when creating multiple transactions. ```javascript const nonce = await apiKit.getNextNonce(safeAddress) ``` -------------------------------- ### Create and Execute a Transaction using SDK Starter Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and execute a transaction with the SDK Starter Kit. It deploys the Safe account if it doesn't exist and uses the Safe Transaction Service for multi-owner confirmations. ```bash pnpm play send-transactions ``` -------------------------------- ### Create and Execute Off-Chain Messages using SDK Starter Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and execute off-chain messages with the SDK Starter Kit. It deploys the Safe account if it doesn't exist and uses the Safe Transaction Service for multi-owner confirmations. ```bash pnpm play send-off-chain-message ``` -------------------------------- ### Create and Execute On-Chain Messages using SDK Starter Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and execute on-chain messages with the SDK Starter Kit. It deploys the Safe account if it doesn't exist and uses the Safe Transaction Service for multi-owner confirmations. ```bash pnpm play send-on-chain-message ``` -------------------------------- ### Create and Execute Safe Operations using SDK Starter Kit Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and execute a Safe Operation with the SDK Starter Kit. It deploys the Safe account if it doesn't exist and uses the Safe Transaction Service for multi-owner confirmations. ```bash pnpm play send-safe-operation ``` -------------------------------- ### Initialize Protocol Kit with Deployed Safe Source: https://github.com/safe-global/safe-core-sdk/blob/main/packages/protocol-kit/README.md Initialize the Protocol Kit SDK with an already deployed Safe address. Requires a provider, optional signer, and the safeAddress. ```javascript import Safe from '@safe-global/protocol-kit' const protocolKit = await Safe.init({ provider, signer, safeAddress }) ``` -------------------------------- ### Create and Execute a Safe Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Demonstrates the typical flow for creating, signing, and executing a Safe transaction using the `protocol-kit`. ```bash pnpm play create-and-execute-transaction ``` -------------------------------- ### Initialize Protocol Kit with Custom Contract Networks Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Initialize the Protocol Kit when Safe contracts are not deployed on the current network. Requires specifying contract addresses and ABIs via `contractNetworks`. ```javascript import { ContractNetworksConfig, SafeProvider } from '@safe-global/protocol-kit' const safeProvider = new SafeProvider({ provider, signer }) const chainId = await safeProvider.getChainId() const contractNetworks: ContractNetworksConfig = { [chainId]: { safeSingletonAddress: '', safeProxyFactoryAddress: '', multiSendAddress: '', multiSendCallOnlyAddress: '', fallbackHandlerAddress: '', signMessageLibAddress: '', createCallAddress: '', simulateTxAccessorAddress: '', safeWebAuthnSignerFactoryAddress:'', safeSingletonAbi: '', // Optional. safeProxyFactoryAbi: '', // Optional. multiSendAbi: '', // Optional. multiSendCallOnlyAbi: '', // Optional. fallbackHandlerAbi: '', // Optional. signMessageLibAbi: '', // Optional. createCallAbi: '', // Optional. simulateTxAccessorAbi: '' // Optional. safeWebAuthnSignerFactoryAbi: '' // Optional. } } const protocolKit = await Safe.init({ provider, signer, safeAddress, contractNetworks }) ``` -------------------------------- ### API Kit Interoperability for User Operations Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create a User Operation, store it using the Safe Transaction Service, orchestrate signatures, and send it to bundler services. ```bash pnpm play userop-api-kit-interoperability ``` -------------------------------- ### Initialize Protocol Kit forcing Safe.sol Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Initialize the Protocol Kit and force the use of the Safe.sol contract by setting `isL1SafeSingleton` to true. This is useful for L1 networks or when specific contract behavior is needed. ```javascript const protocolKit = await Safe.init({ provider, signer, safeAddress, isL1SafeSingleton: true }) ``` -------------------------------- ### Run Playground Commands Source: https://github.com/safe-global/safe-core-sdk/blob/main/CONTRIBUTING.md Execute commands within the project's playground for manual testing. Replace `` with the desired command. ```bash pnpm play ``` -------------------------------- ### Run All Project Tests Source: https://github.com/safe-global/safe-core-sdk/blob/main/CONTRIBUTING.md Execute all tests across all packages in the monorepo from the project root. ```bash pnpm test ``` -------------------------------- ### Execute Safe Deployment and Reconnect Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md After obtaining the `deploymentTransaction`, execute it using your Ethereum client. Once deployed, reconnect the `protocolKit` instance to the new Safe address using the `connect` method to interact with the deployed Safe. ```javascript // Execute this transaction using the Ethereum client of your choice const txHash = await client.sendTransaction({ to: deploymentTransaction.to, value: BigInt(deploymentTransaction.value), data: `0x${deploymentTransaction.data}` }) console.log('Transaction hash:', txHash) const txReceipt = await waitForTransactionReceipt(client, { hash: txHash }) // Extract the Safe address from the deployment transaction receipt const safeAddress = getSafeAddressFromDeploymentTx(txReceipt, safeVersion) console.log('safeAddress:', safeAddress) // Reinitialize the instance of protocol-kit using the obtained Safe address protocolKit.connect({ safeAddress }) console.log('is Safe deployed:', await protocolKit.isSafeDeployed()) console.log('Safe Address:', await protocolKit.getAddress()) console.log('Safe Owners:', await protocolKit.getOwners()) console.log('Safe Threshold:', await protocolKit.getThreshold()) ``` -------------------------------- ### Initialize Protocol Kit with Undeployed Safe Source: https://github.com/safe-global/safe-core-sdk/blob/main/packages/protocol-kit/README.md Initialize the Protocol Kit SDK with configuration for an undeployed Safe using predictedSafe properties. This allows interaction before deployment. ```javascript import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit' const predictedSafe: PredictedSafeProps = { safeAccountConfig, safeDeploymentConfig } const protocolKit = await Safe.init({ provider, signer, predictedSafe }) ``` -------------------------------- ### Execute Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Retrieve a transaction with signatures and execute it using the Protocol Kit. Optionally, validate the transaction before execution. ```javascript const safeTransaction = await apiKit.getTransaction(...) const executeTxResponse = await protocolKit.executeTransaction(safeTransaction) const receipt = executeTxResponse.transactionResponse && (await executeTxResponse.transactionResponse.wait()) ``` ```javascript const isValidTx = await protocolKit.isValidTransaction(safeTransaction) ``` -------------------------------- ### Deploy a Safe Account Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to deploy a new Safe account with custom configuration, such as the number of signers, their addresses, and the threshold. ```bash pnpm play deploy-safe ``` -------------------------------- ### Run Tests for Individual Packages Source: https://github.com/safe-global/safe-core-sdk/blob/main/CONTRIBUTING.md Filter and run tests for a specific package after building the entire project. Replace `` with the target package. ```bash pnpm --filter test ``` ```bash pnpm --filter @safe-global/protocol-kit test ``` ```bash pnpm --filter @safe-global/api-kit test ``` -------------------------------- ### Initialize Safe API Kit with Custom Transaction Service URL Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Instantiate the SafeApiKit with both chain ID and a custom transaction service URL for networks where Safe does not run a service. ```javascript const apiKit = new SafeApiKit({ chainId, txServiceUrl: 'https://txServiceUrl.com' }) ``` -------------------------------- ### Initialize SafeApiKit Source: https://github.com/safe-global/safe-core-sdk/blob/main/packages/api-kit/README.md Initialize the SafeApiKit with a chain ID and an optional custom transaction service URL. ```javascript import SafeApiKit from '@safe-global/api-kit' const apiKit = new SafeApiKit({ chainId: 1n, // Optional. txServiceUrl must be used to set a custom service. For example on chains where Safe doesn't run services. txServiceUrl: 'https://safe-transaction-mainnet.safe.global' }) ``` -------------------------------- ### Generate a Custom Safe Address Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md This script demonstrates how to deterministically generate a Safe account address based on configuration parameters like signers and threshold. Useful for counterfactual deployments or multi-chain scenarios. ```bash pnpm play generate-safe-address ``` -------------------------------- ### Generate a Changeset Source: https://github.com/safe-global/safe-core-sdk/blob/main/CONTRIBUTING.md Create a changeset file to describe changes affecting published packages. This is used for versioning and changelog generation. ```bash pnpm changeset ``` -------------------------------- ### Initialize Safe API Kit with Chain ID Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Instantiate the SafeApiKit by providing the chain ID. This is sufficient for networks where Safe runs a Transaction Service. ```javascript import SafeApiKit from '@safe-global/api-kit' const apiKit = new SafeApiKit({ chainId }) ``` -------------------------------- ### Replicate Safe Addresses Across Networks Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md This script shows how to obtain the same Safe address on different networks, useful for maintaining a consistent address when deploying on multiple chains. ```bash pnpm play replicate-safe-address ``` -------------------------------- ### Send User Operation with a verifying Paymaster and a non-existent Safe account Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and send a User Operation for a non-existent Safe account, sponsored by a verifying Paymaster. ```bash pnpm play userop-verifying-paymaster-counterfactual ``` -------------------------------- ### Send User Operation with an existing Safe and a verifying Paymaster Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and send a User Operation with an existing Safe, sponsored by a verifying Paymaster. ```bash pnpm play userop-verifying-paymaster ``` -------------------------------- ### Send User Operation using an existing Safe Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and send a User Operation from a batch of transactions using an existing Safe account. ```bash pnpm play userop ``` -------------------------------- ### Send User Operation with an existing Safe and an ERC20 Paymaster Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and send a User Operation with an existing Safe, covering gas costs with ERC20 tokens via a paymaster. ```bash pnpm play userop-erc20-paymaster ``` -------------------------------- ### Execute User Operations in parallel Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to execute multiple User Operations in parallel using custom nonces. ```bash pnpm play userop-parallel-execution ``` -------------------------------- ### Send User Operation with an ERC20 Paymaster and a non-existent Safe account Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and send a User Operation for a non-existent Safe account, with gas costs covered by an ERC20 paymaster. ```bash pnpm play userop-erc20-paymaster-counterfactual ``` -------------------------------- ### Relay Sponsored Transaction using Gelato Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to execute a transaction via a Gelato relay, with fees sponsored by a third-party account. ```bash pnpm play gelato-sponsored-transaction ``` -------------------------------- ### Send User Operation with a non-existent Safe account Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to create, sign, and send a User Operation for a non-existent Safe account. ```bash pnpm play userop-counterfactual ``` -------------------------------- ### Relay Transaction using Gelato Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to execute a transaction via a Gelato relay, with fees deducted from the Safe balance. ```bash pnpm play gelato-paid-transaction ``` -------------------------------- ### Estimate Gas for a Safe Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Showcases how to estimate both the complete transaction gas cost (`gas`) and the specific Safe contract calls gas cost (`safeTxGas`). ```bash pnpm play estimate-gas ``` -------------------------------- ### Create a New Safe Deployment Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Use `createSafeDeploymentTransaction` to generate an Ethereum transaction for deploying a new Safe. Configure owners and threshold as needed. This method returns a transaction object ready for execution. ```javascript import { SafeAccountConfig } from '@safe-global/protocol-kit' const safeAccountConfig: SafeAccountConfig = { owners: ['0x...', '0x...', '0x...'], threshold: 2 // Additional optional parameters can be included here } const predictSafe = { safeAccountConfig, safeDeploymentConfig: { saltNonce, // optional parameter safeVersion // optional parameter } } const protocolKit = await Safe.init({ provider, signer, predictSafe }) const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction() // Execute this transaction using the Ethereum client of your choice const txHash = await client.sendTransaction({ to: deploymentTransaction.to, value: BigInt(deploymentTransaction.value), data: `0x${deploymentTransaction.data}` }) ``` -------------------------------- ### Execute a Transaction from Safe Transaction Service Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Once sufficient signatures are collected for a transaction in the Safe Transaction Service, this script allows any account to retrieve and execute the transaction. ```bash pnpm play execute-transaction ``` -------------------------------- ### Propose a Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Propose a transaction to the Safe Transaction Service. Requires the Safe address, transaction data, transaction hash, sender address, and sender signature. ```javascript const safeTxHash = await protocolKit.getTransactionHash(safeTransaction) const senderSignature = await protocolKit.signHash(safeTxHash) await apiKit.proposeTransaction({ safeAddress, safeTransactionData: safeTransaction.data, safeTxHash, senderAddress, senderSignature: senderSignature.data, origin }) ``` -------------------------------- ### Propose a Transaction via Safe Transaction Service Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Allows a Safe signer to propose a transaction by submitting it to the Safe Transaction Service for other signers to review. ```bash pnpm play propose-transaction ``` -------------------------------- ### Validate Signatures for a Safe Message Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Use this script to validate the signatures associated with a Safe message using the `protocol-kit`. ```bash pnpm play validate-signatures ``` -------------------------------- ### Create MultiSend Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Use this snippet to create a MultiSend transaction with multiple MetaTransactionData objects and optional properties. Ensure necessary imports are included. ```javascript import { SafeTransactionOptionalProps } from '@safe-global/protocol-kit' import { MetaTransactionData } from '@safe-global/types-kit' const transactions: MetaTransactionData[] = [ { to, data, value, operation }, { to, data, value, operation } // ... ] const options: SafeTransactionOptionalProps = { safeTxGas, // Optional baseGas, // Optional gasPrice, // Optional gasToken, // Optional refundReceiver, // Optional nonce // Optional } const safeTransaction = await protocolKit.createTransaction({ transactions, options }) ``` -------------------------------- ### Confirm a Proposed Transaction Source: https://github.com/safe-global/safe-core-sdk/blob/main/playground/README.md Enables a Safe signer to confirm a proposed transaction by retrieving it from the Safe Transaction Service, signing it, and submitting the signature. ```bash pnpm play confirm-transaction ``` -------------------------------- ### Confirm Transaction Signature Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Obtain a signature for a transaction hash and add it to the Safe Transaction Service. ```javascript // transaction: SafeMultisigTransactionResponse const hash = transaction.safeTxHash let signature = await protocolKit.signHash(hash) await apiKit.confirmTransaction(hash, signature.data) ``` -------------------------------- ### Check if Transaction Signed by Address Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Use this function to determine if a specific owner's address has already signed a Safe transaction. It iterates through the transaction's confirmations to find a match. ```typescript const isTransactionSignedByAddress = ( signerAddress: string, transaction: SafeMultisigTransactionResponse ) => { const confirmation = transaction.confirmations.find( (confirmation) => confirmation.owner === signerAddress ) return !!confirmation } ``` -------------------------------- ### Check if Transaction is Executable Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md This function checks if a Safe transaction has reached the required number of confirmations to be executed. It compares the current number of confirmations against the Safe's threshold. ```typescript const isTransactionExecutable = ( safeThreshold: number, transaction: SafeMultisigTransactionResponse ) => { return transaction.confirmations.length >= safeThreshold } ``` -------------------------------- ### SafeMultisigTransactionResponse Type Source: https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md Defines the structure of a Safe multisig transaction response object returned by the Safe Transaction Service. ```typescript type SafeMultisigTransactionResponse = { safe: string to: string value: string data?: string operation: number gasToken: string safeTxGas: string baseGas: string gasPrice: string refundReceiver?: string nonce: string executionDate: string | null submissionDate: string modified: string blockNumber?: number transactionHash: string | null safeTxHash: string executor: string | null proposer: string | null proposedByDelegate: string | null isExecuted: boolean isSuccessful: boolean | null ethGasPrice: string | null maxFeePerGas: string | null maxPriorityFeePerGas: string | null gasUsed: number | null fee: string | null origin: string dataDecoded?: { method: string parameters: [ { name: string type: string value: string valueDecoded?: ValueDecoded[] } ] } confirmationsRequired: number confirmations?: [ { owner: string submissionDate: string transactionHash?: string confirmationType?: string signature: string signatureType?: SignatureType }, // ... ] signatures?: string } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.