Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: [EIP-1193] Update Protocol Kit initialization #461

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions pages/core-api/transaction-service-guides/delegates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
```typescript
import { ethers } from 'ethers'
import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit'
import { EthersAdapter } from '@safe-global/protocol-kit'
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -65,22 +64,11 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ethProvider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner A
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerA = new EthersAdapter({
ethers,
signerOrProvider: ownerA
})

// Initialize the API Kit
const apiKit = new SafeApiKit({
chainId: 11155111n
})

const ownerAAddress = await ethAdapterOwnerA.getSignerAddress()

// Get the Safe delegates
const delegates = await apiKit.getSafeDelegates({
delegatorAddress: config.SAFE_ADDRESS
Expand Down Expand Up @@ -118,15 +106,13 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, ethProvider)
const provider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner B
const ethAdapterOwnerB = new EthersAdapter({
ethers,
signerOrProvider: ownerB
})
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, provider)
const ownerAAddress = await ownerA.getAddress()

const ownerBAddress = await ethAdapterOwnerB.getSignerAddress()
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, provider)
const ownerBAddress = await ownerB.getAddress()

const delegateConfig: AddSafeDelegateProps = {
delegateAddress: ownerBAddress || '0x',
Expand Down
30 changes: 8 additions & 22 deletions pages/core-api/transaction-service-guides/messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```bash
yarn add ethers @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
yarn add @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -41,9 +41,8 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```typescript
import { ethers } from 'ethers'
import SafeApiKit, { AddMessageProps } from '@safe-global/api-kit'
import Safe, { EthersAdapter, hashSafeMessage } from '@safe-global/protocol-kit'
import Safe, { hashSafeMessage } from '@safe-global/protocol-kit'
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -67,18 +66,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ethProvider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner A
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerA = new EthersAdapter({
ethers,
signerOrProvider: ownerA
})

// Initialize the Protocol Kit with Owner A
const protocolKitOwnerA = await Safe.create({
ethAdapter: ethAdapterOwnerA,
provider: config.RPC_URL,
signer: config.OWNER_A_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down Expand Up @@ -194,16 +185,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
// Instantiate an EthAdapter with Owner B
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerB = new EthersAdapter({
ethers,
signerOrProvider: ownerB
})

// Initialize the Protocol Kit with Owner B
const protocolKitOwnerB = await Safe.create({
ethAdapter: ethAdapterOwnerB,
provider: config.RPC_URL,
signer: config.OWNER_B_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down Expand Up @@ -243,7 +228,8 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
// Sign the message with Owner B
const signedMessageOwnerB = await protocolKitOwnerB.signMessage(safeServiceMessage)

const ownerBAddress = (await ethAdapterOwnerB.getSignerAddress()) || '0x'
// Get Owner B address
const ownerBAddress = '0x...'

// Send the message to the Transaction Service with the signature from Owner B
await apiKit.addMessageSignature(
Expand Down
31 changes: 7 additions & 24 deletions pages/core-api/transaction-service-guides/transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```bash
yarn add ethers @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
yarn add @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -41,9 +41,8 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```typescript
import { ethers } from 'ethers'
import SafeApiKit from '@safe-global/api-kit'
import Safe, { EthersAdapter } from '@safe-global/protocol-kit'
import Safe from '@safe-global/protocol-kit'
import {
MetaTransactionData,
OperationType
Expand All @@ -69,18 +68,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ethProvider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner A
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerA = new EthersAdapter({
ethers,
signerOrProvider: ownerA
})

// Initialize the Protocol Kit with Owner A
const protocolKitOwnerA = await Safe.create({
ethAdapter: ethAdapterOwnerA,
provider: config.RPC_URL,
signer: config.OWNER_A_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down Expand Up @@ -176,14 +167,12 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
chainId: 11155111n
})

const senderAddress = await ownerA.getAddress()

// Send the transaction to the Transaction Service with the signature from Owner A
await apiKit.proposeTransaction({
safeAddress: config.SAFE_ADDRESS,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress,
senderAddress: config.OWNER_A_ADDRESS,
senderSignature: signatureOwnerA.data
})
```
Expand Down Expand Up @@ -242,16 +231,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
// Instantiate an EthAdapter with Owner B
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerB = new EthersAdapter({
ethers,
signerOrProvider: ownerB
})

// Initialize the Protocol Kit with Owner B
const protocolKitOwnerB = await Safe.create({
ethAdapter: ethAdapterOwnerB,
provider: config.RPC_URL,
signer: config.OWNER_B_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down
Loading
Loading