diff --git a/pages/sdk/protocol-kit/reference/safe.mdx b/pages/sdk/protocol-kit/reference/safe.mdx index a8d7ce3c..d771f949 100644 --- a/pages/sdk/protocol-kit/reference/safe.mdx +++ b/pages/sdk/protocol-kit/reference/safe.mdx @@ -1,4 +1,4 @@ -import { Callout } from 'nextra/components' +import { Tabs, Callout } from 'nextra/components' # Safe reference @@ -6,11 +6,7 @@ import { Callout } from 'nextra/components' ### `init` -Returns an instance of the Protocol Kit connected to a Safe. - -The `provider` property can be an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compatible provider or an RPC URL. The `signer` property can be the signer address or its private key. The provided Safe must be a `safeAddress` or a `predictedSafe`. - -Initialization of a deployed Safe using the `safeAddress` property: +The `init` method initializes the Protocol Kit instance and connects the Safe account. ```typescript import Safe from '@safe-global/protocol-kit' @@ -18,46 +14,153 @@ import Safe from '@safe-global/protocol-kit' const protocolKit = await Safe.init({ provider, signer, - safeAddress + safeAddress // or predictedSafe }) ``` -Initialization of an undeployed Safe using the `predictedSafe` property. Because Safes are deployed in a deterministic way, passing a `predictedSafe` will allow to initialize the SDK with the Safe configuration and use it to some extent before it's deployed: - -```typescript -import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit' - -const predictedSafe: PredictedSafeProps = { - safeAccountConfig, - safeDeploymentConfig -} - -const protocolKit = await Safe.init({ - provider, - signer, - predictedSafe -}) -``` - -- The `signer` property - - A passkey object can be passed as a signer to initialize an instance of the Protocol Kit. - -```typescript -import Safe from '@safe-global/protocol-kit' +- The `safeAddress` property is the address of the Safe account. Use this property if the Safe is already deployed. + +- The `predictedSafe` property is an object that contains the Safe account configuration and deployment details. Using this property allows initializing the Protocol Kit with limited functionality, with a Safe account that has yet to be deployed. This object contains the following properties: + + - `safeAccountConfig`: + - `owners`: An array of Safe owner addresses. + - `threshold`: The number of signatures required to execute a Safe transaction. + - `to` (optional): The contract address for optional delegate call. + - `data` (optional): The data payload for optional delegate call. + - `fallbackHandler` (optional): The fallback handler address. + - `paymentToken` (optional): The token that should be used for the payment (0 is ETH). + - `payment` (optional): The value that should be paid. + - `paymentReceiver` (optional): The address that should receive the payment (or 0 if tx.origin). + - `safeDeploymentConfig`: + - `saltNonce` (optional): The salt nonce to use. Changing this value will update the predicted Safe account address. + - `safeVersion` (optional): The Safe contract version to use. + - `deploymentType` (optional): The Safe deployment type to use. It can be `canonical`, `eip155`, or `zksync`. Changing this value affects the search algorithm used to find the [Safe deployment address](https://github.com/safe-global/safe-deployments/tree/main/src/assets) for any Safe contract, resulting in a change to the predicted address. + +Depending on whether the Safe account is deployed or not, you can initialize the Protocol Kit in two different ways: + +{/* */} + + + + Initialization of a deployed Safe using the `safeAddress` property. + + ```typescript + import Safe from '@safe-global/protocol-kit' + + const protocolKit = await Safe.init({ + provider, + signer, + safeAddress: '0x...' + }) + ``` + + + Initialization of an undeployed Safe using the `predictedSafe` property. Passing a `predictedSafe` allows the Protocol Kit to be initialized with the Safe configuration, as it's calculated deterministically, using it with limited functionality before deployment. + + ```typescript + import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit' + + const predictedSafe: PredictedSafeProps = { + safeAccountConfig, + safeDeploymentConfig + } -const passkey: PasskeyArgType = { - rawId, - coordinates, -} + const protocolKit = await Safe.init({ + provider, + signer, + predictedSafe + }) + ``` + + + +{/* */} + +- The `provider` property can be an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compatible provider or an RPC URL. + +{/* */} + + + + ```typescript + import Safe from '@safe-global/protocol-kit' + + const rpcURL = 'https://sepolia.infura.io/v3/...' + + const protocolKit = await Safe.init({ + provider: rpcURL, + signer, + safeAddress: '0x...' + }) + ``` + + + ```typescript + import Safe from '@safe-global/protocol-kit' + + const eip1193 = window.ethereum + + const protocolKit = await Safe.init({ + provider: eip1193, + signer, + safeAddress: '0x...' + }) + ``` + + + +{/* */} + +- The `signer` property can be a Safe owner address, its private key or a passkey object. + +{/* */} + + + + ```typescript + import Safe from '@safe-global/protocol-kit' + + const signerAddress = '0x...' + + const protocolKit = await Safe.init({ + provider, + signer: signerAddress, + safeAddress: '0x...' + }) + ``` + + + ```typescript + import Safe from '@safe-global/protocol-kit' + + const privateKey = '0x...' + + const protocolKit = await Safe.init({ + provider, + signer: privateKey, + safeAddress: '0x...' + }) + ``` + + + ```typescript + import Safe, { PasskeyArgType } from '@safe-global/protocol-kit' + + const passkey: PasskeyArgType = { + rawId, + coordinates, + } -const protocolKit = await Safe.init({ - provider, - signer: passkey, - // safeAddress or predictedSafe -}) -``` + const protocolKit = await Safe.init({ + provider, + signer: passkey, + safeAddress: '0x...' + }) + ``` + + +{/* */} - The `isL1SafeSingleton` flag @@ -275,7 +378,7 @@ Returns a transaction object ready to be executed and deploy a new Safe. Before deploying a new Safe, you must initialize and configure the Protocol Kit. ```typescript -const predictSafe = { +const predictedSafe = { safeAccountConfig: { owners: ['0x...', '0x...', '0x...'], threshold: 2 @@ -283,14 +386,15 @@ const predictSafe = { }, safeDeploymentConfig: { saltNonce, // Optional - safeVersion // Optional + safeVersion, // Optional + deploymentType // Optional } } let protocolKit = await Safe.init({ provider, signer, - predictSafe + predictedSafe }) const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction()