Skip to content

Commit

Permalink
fix(safe-core-sdk). init method docs (#611)
Browse files Browse the repository at this point in the history
* Improve docs

* valve

* vale

* Improve writing

* Improve provider and signer docs

* vale

* Update pages/sdk/protocol-kit/reference/safe.mdx

Co-authored-by: Daniel <[email protected]>

* Remove line

* Moving things around

* Apply suggestions from code review

* Add little adjustments

---------

Co-authored-by: Daniel <[email protected]>
Co-authored-by: Germán Martínez <[email protected]>
Co-authored-by: Germán Martínez <[email protected]>
  • Loading branch information
4 people authored Oct 8, 2024
1 parent 3d1bcab commit 7e082a8
Showing 1 changed file with 147 additions and 43 deletions.
190 changes: 147 additions & 43 deletions pages/sdk/protocol-kit/reference/safe.mdx
Original file line number Diff line number Diff line change
@@ -1,63 +1,166 @@
import { Callout } from 'nextra/components'
import { Tabs, Callout } from 'nextra/components'

# Safe reference

## Initialization

### `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'

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:

{/* <!-- vale off --> */}

<Tabs items={['deployed-safe.ts', 'undeployed-safe.ts']}>
<Tabs.Tab>
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...'
})
```
</Tabs.Tab>
<Tabs.Tab>
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
})
```
</Tabs.Tab>
</Tabs>

{/* <!-- vale on --> */}

- The `provider` property can be an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compatible provider or an RPC URL.

{/* <!-- vale off --> */}

<Tabs items={["url.ts", "eip1193.ts"]}>
<Tabs.Tab>
```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...'
})
```
</Tabs.Tab>
<Tabs.Tab>
```typescript
import Safe from '@safe-global/protocol-kit'

const eip1193 = window.ethereum

const protocolKit = await Safe.init({
provider: eip1193,
signer,
safeAddress: '0x...'
})
```
</Tabs.Tab>
</Tabs>
{/* <!-- vale on --> */}
- The `signer` property can be a Safe owner address, its private key or a passkey object.
{/* <!-- vale off --> */}
<Tabs items={["address.ts", "private-key.ts", "passkey.ts"]}>
<Tabs.Tab>
```typescript
import Safe from '@safe-global/protocol-kit'

const signerAddress = '0x...'

const protocolKit = await Safe.init({
provider,
signer: signerAddress,
safeAddress: '0x...'
})
```
</Tabs.Tab>
<Tabs.Tab>
```typescript
import Safe from '@safe-global/protocol-kit'

const privateKey = '0x...'

const protocolKit = await Safe.init({
provider,
signer: privateKey,
safeAddress: '0x...'
})
```
</Tabs.Tab>
<Tabs.Tab>
```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...'
})
```
</Tabs.Tab>
</Tabs>
{/* <!-- vale on --> */}
- The `isL1SafeSingleton` flag
Expand Down Expand Up @@ -275,22 +378,23 @@ 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
// ...
},
safeDeploymentConfig: {
saltNonce, // Optional
safeVersion // Optional
safeVersion, // Optional
deploymentType // Optional
}
}

let protocolKit = await Safe.init({
provider,
signer,
predictSafe
predictedSafe
})

const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction()
Expand Down

0 comments on commit 7e082a8

Please sign in to comment.