Skip to content

Commit 8b9df00

Browse files
authored
feat: Improve playgrounds information (safe-global#1175)
* Improve README's * Add env vars info
1 parent a57a757 commit 8b9df00

24 files changed

+200
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ If you are interested in contributing, please read the [Contributing Guidelines]
4646

4747
## Playground
4848

49-
This project includes a [playground](https://github.com/safe-global/safe-core-sdk/tree/main/playground/README.md) with a few scripts that can be used as a starting point to use the Safe{Core} SDK.
49+
This project includes a [playground](https://github.com/safe-global/safe-core-sdk/tree/main/playground/README.md) with a few scripts that can be used as a starting point to use the Safe{Core} SDK. These scripts contain valuable snippets that demonstrate various Safe features. They serve as a useful learning tool or starting point for implementing these features in your application.
5050

5151
## License
5252

playground/README.md

Lines changed: 158 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ yarn install
99
yarn build
1010
```
1111

12-
Update the config inside the scripts you want to execute and run the following commands for each of them.
12+
Update the config inside the scripts you want to execute and run the following commands for each of them. There are 2 ways to configure the input parameters of the scripts:
13+
14+
- Environment files can be found in each folder with the required configuration. In this case, rename the `.env-sample` file to `.env` and update the values according to the comments inside `.env-sample`.
15+
- Set the values directly in the script file.
16+
17+
### `protocol-kit`
1318

1419
#### Deploy a Safe
1520

@@ -19,9 +24,51 @@ This script allows to deploy a new Safe account with any given configuration (nu
1924
yarn play deploy-safe
2025
```
2126

27+
#### Generate a custom Safe address
28+
29+
This script shows how to generate a Safe address based on some custom config parameters. The Safe account address is deterministic and can be calculated based on the signers and threshold. This is useful for counterfactual deployments or multi-chain Safe accounts scenarios:
30+
31+
```bash
32+
yarn play generate-safe-address
33+
```
34+
35+
#### Estimate gas
36+
37+
Showcase how to estimate the `gas` (The complete transaction gas cost) and `safeTxGas` (The concrete Safe contracts calls gas cost) for a transaction:
38+
39+
```bash
40+
yarn play estimate-gas
41+
```
42+
43+
#### Create and execute a transaction
44+
45+
This script allows you to create and execute a transaction. It demonstrates the typical flow for a Safe transaction using the `protocol-kit`, including how to create, sign, and execute a transaction.
46+
47+
```bash
48+
yarn play create-and-execute-transaction
49+
```
50+
51+
#### Replicate Safe addresses
52+
53+
This script demonstrates how to obtain the same Safe address across different networks. This is useful when you want to deploy a Safe account on another network while retaining the same Safe account address:
54+
55+
```bash
56+
yarn play replicate-safe-address
57+
```
58+
59+
#### Validate signatures
60+
61+
This script shows how to validate the signatures of a Safe message using the `protocol-kit`:
62+
63+
```bash
64+
yarn play validate-signatures
65+
```
66+
67+
### `api-kit`
68+
2269
#### Propose a transaction
2370

24-
This script allows a signer of a Safe to share a transaction with the other signers by submitting it to the Safe Transaction Service:
71+
This script allows a signer of a Safe to share a transaction with the other signers by submitting it to the Safe Transaction Service first:
2572

2673
```bash
2774
yarn play propose-transaction
@@ -43,22 +90,126 @@ Once there are enough signatures collected for a given transaction in the Safe T
4390
yarn play execute-transaction
4491
```
4592

93+
### `relay-kit`
94+
95+
#### Send User Operation using an existing Safe
96+
97+
This script showcases how to create a Safe Operation from a batch of transactions, sign it and send to the bundler as an User Operation:
98+
99+
```bash
100+
yarn play userop
101+
```
102+
103+
#### Send User Operation with a non-existent Safe account
104+
105+
This script demonstrates how to create a Safe Operation from a batch of transactions, sign it and send to the bundler as an User Operation for a non-existent Safe account:
106+
107+
```bash
108+
yarn play userop-counterfactual
109+
```
110+
111+
#### Send User Operation using an existing Safe and an ERC20 Paymaster
112+
113+
This script showcases how to create a Safe Operation from a batch of transactions, sign it and send to the bundler as an User Operation. The User Operation gas costs will be covered with ERC20 tokens by using a paymaster:
114+
115+
```bash
116+
yarn play userop-erc20-paymaster
117+
```
118+
119+
#### Send User Operation using an ERC20 Paymaster with a non-existent Safe account
120+
121+
This script showcases how to create a Safe Operation from a batch of transactions, sign it and send to the bundler as an User Operation for a non-existent Safe account. The User Operation gas costs will be covered with ERC20 tokens by using a paymaster:
122+
123+
```bash
124+
yarn play userop-erc20-paymaster-counterfactual
125+
```
126+
127+
#### Send User Operation using an existing Safe and a verifying Paymaster to sponsor the operation
128+
129+
This script showcases how to create a Safe Operation from a batch of transactions, sign it and send to the bundler. The User Operation will be sponsored by using a Paymaster:
130+
131+
```bash
132+
yarn play userop-verifying-paymaster
133+
```
134+
135+
#### Send User Operation using a verifying Paymaster tp sponsor the operations with a non-existent Safe account
136+
137+
This script demonstrates how to create a Safe Operation from a batch of transactions, sign it and send to the bundler for a non-existent Safe account. The User Operation will be sponsored by using a Paymaster:
138+
139+
```bash
140+
yarn play userop-verifying-paymaster-counterfactual
141+
```
142+
143+
#### Execute User Operations in parallel
144+
145+
This script showcases how to execute multiple User Operations in parallel by using custom nonces:
146+
147+
```bash
148+
yarn play userop-parallel-execution
149+
```
150+
151+
#### Api kit interoperability
152+
153+
This script shows how to create a Safe Operation and store it using the Safe Transaction Service. This process orchestrates signatures from additional owners before bundle the User Operation and send it to provider bundler services:
154+
155+
```bash
156+
yarn play userop-api-kit-interoperability
157+
```
158+
159+
#### Relay a transaction using Gelato
160+
46161
In case you want to execute the transaction via a transaction relay, this script allows to do that, where the fees are extracted from the Safe balance:
47162

48163
```bash
49-
yarn play relay-paid-transaction
164+
yarn play gelato-paid-transaction
50165
```
51166

167+
#### Relay an sponsored transaction using Gelato
168+
52169
In case you want to execute the transaction via a transaction relay, this script allows to to that, where the fees are extracted from a third party account balance that sponsors the transaction:
53170

54171
```bash
55-
yarn play relay-sponsored-transaction
172+
yarn play gelato-sponsored-transaction
56173
```
57174

58-
#### Generate a custom Safe address
175+
### `sdk-starter-kit`
176+
177+
#### Create and execute a transaction
59178

60-
This script allows to find the right `saltNonce` to generate a vanity Safe address with any given configuration:
179+
This script demonstrates how to use the `sdk-starter-kit` to create, sign, and execute a transaction and deploy the Safe account if it does not exist. Internally it use the Safe Transaction Service to propose and confirm the transactions in case more than one owner signature is required:
61180

62181
```bash
63-
yarn play generate-safe-address
182+
yarn play send-transactions
183+
```
184+
185+
#### Create and execute Safe Operations
186+
187+
This script demonstrates how to use the `sdk-starter-kit` to create, sign, and execute a Safe Operation and deploy the Safe account if it does not exist. Internally it use the Safe Transaction Service to propose and confirm the Safe Operations in case more than one owner signature is required:
188+
189+
```bash
190+
yarn play send-safe-operation
191+
```
192+
193+
#### Create and execute on-chain messages
194+
195+
This script demonstrates how to use the `sdk-starter-kit` to create, sign, and execute on-chain messages and deploy the Safe account if it does not exist. Internally it use the Safe Transaction Service to propose and confirm the on-chain messages (that are basically regular transactions) in case more than one owner signature is required:
196+
197+
```bash
198+
yarn play send-on-chain-message
199+
```
200+
201+
#### Create and execute off-chain messages
202+
203+
This script demonstrates how to use the `sdk-starter-kit` to create, sign, and execute off-chain messages and deploy the Safe account if it does not exist. Internally it use the Safe Transaction Service to propose and confirm the off-chain messages in case more than one owner signature is required:
204+
205+
```bash
206+
yarn play send-off-chain-message
207+
```
208+
209+
#### Setup Safe account owners
210+
211+
This script demonstrates how to use the `sdk-starter-kit` to setup Safe accounts with different owner configurations
212+
213+
```bash
214+
yarn play owner-management
64215
```

playground/api-kit/confirm-transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Config {
1111
SAFE_TX_HASH: string
1212
}
1313

14+
// Adjust the configuration with your own input parameters before running the script
1415
const config: Config = {
1516
CHAIN_ID: 11155111n,
1617
RPC_URL: 'https://sepolia.gateway.tenderly.co',

playground/api-kit/execute-transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface Config {
1313
SAFE_TX_HASH: string
1414
}
1515

16+
// Adjust the configuration with your own input parameters before running the script
1617
const config: Config = {
1718
CHAIN_ID: 11155111n,
1819
RPC_URL: 'https://sepolia.gateway.tenderly.co',

playground/api-kit/propose-transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Config {
1111
SAFE_ADDRESS: string
1212
}
1313

14+
// Adjust the configuration with your own input parameters before running the script
1415
const config: Config = {
1516
CHAIN_ID: 11155111n,
1617
RPC_URL: 'https://sepolia.gateway.tenderly.co',

playground/protocol-kit/create-execute-transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface Config {
1717
SAFE_ADDRESS: string
1818
}
1919

20+
// Adjust the configuration with your own input parameters before running the script
2021
const config: Config = {
2122
RPC_URL: 'https://sepolia.gateway.tenderly.co',
2223
SIGNER_ADDRESS_PRIVATE_KEY: SIGNER_ADDRESS_PRIVATE_KEY!,

playground/protocol-kit/deploy-safe.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface Config {
2020
}
2121
}
2222

23+
// Adjust the configuration with your own input parameters before running the script
2324
const config: Config = {
2425
RPC_URL: sepolia.rpcUrls.default.http[0],
2526
DEPLOYER_ADDRESS_PRIVATE_KEY: '<DEPLOYER_ADDRESS_PRIVATE_KEY>',

playground/protocol-kit/estimate-gas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Safe, { estimateSafeTxGas } from '@safe-global/protocol-kit'
22
import { Chain, gnosis, arbitrum, polygon } from 'viem/chains'
33
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
44

5+
// Adjust the configuration with your own input parameters before running the script
56
const config = {
67
SAFE_ADDRESS: '<SAFE_ADDRESS>',
78
chain: gnosis // Add the viem chain where the SAFE_ADDRESS is deployed (gnosis, arbitrum, polygon, etc.)

playground/protocol-kit/generate-safe-address.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SafeVersion } from '@safe-global/types-kit'
88

99
// This script can be used to generate a custom Safe address
1010

11+
// Adjust the configuration with your own input parameters before running the script
1112
const config: Config = {
1213
// REQUIRED PARAMETERS
1314
owners: ['0x680cde08860141F9D223cE4E620B10Cd6741037E'],

playground/protocol-kit/replicate-address.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
// This file can be used to play around with the Safe Core SDK
2323

2424
// Safe config to be replicated in different chains
25+
// Adjust the configuration with your own input parameters before running the script
2526
const safeAccountConfig: SafeAccountConfig = {
2627
owners: ['0x0Ee26C4481485AC64BfFf2bdCaA21EdAeCEcdCa9'],
2728
threshold: 1

playground/protocol-kit/validate-signatures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Config {
1111
SIGNER_SAFE_ADDRESS: string
1212
}
1313

14+
// Adjust the configuration with your own input parameters before running the script
1415
// To run this script, you need a Safe with the following configuration
1516
// - 3/3 Safe with 3 owners and threshold 3
1617
// - Owner 1: public address from OWNER1_PRIVATE_KEY

playground/relay-kit/.env-sample

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# Private key of the account used to transfer funds. DEpending on the playground this account should have ETH and/or Test Token
2-
# PIM token can be minted on the Pimlico Dashboard (https://dashboard.pimlico.io/test-erc20-faucet) and can be used for the test transfers and the ERC-20 Paymaster playgrounds
3-
# The derived address will be the Safe owner when using the counterfactual deployment
1+
# Private key of the account used to transfer funds. Depending on the playground this account should have ETH and/or Test Token (PIM tokens)
2+
# PIM tokens can be minted on the Pimlico Dashboard (https://dashboard.pimlico.io/test-erc20-faucet) and can be used for the test transfers and the ERC-20 Paymaster playgrounds
3+
# The derived address will be the Safe owner when using the counterfactual deployment and you should send the test tokens to this address in case the playground requires them
44
PRIVATE_KEY=
5-
# Safe address when using the playgrounds where Safe already exists
5+
# Safe address to use with the playgrounds where Safe must already exist
66
SAFE_ADDRESS=0x...
7+
# Set the preferred RPC url
78
RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
9+
# Set the chain ID where the playgrounds will be used
810
CHAIN_ID=11155111
9-
# You can get Bundler and Paymaster URL's from your provider's dashboard
11+
# You can get the bundler and paymaster URL's from your provider's dashboard
1012
BUNDLER_URL=
1113
PAYMASTER_URL=
14+
# Set the sponsor policy in case you are using one to test the sponsor user operations related playgrounds
1215
SPONSORSHIP_POLICY_ID=

playground/relay-kit/userop-counterfactual.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { privateKeyToAccount } from 'viem/accounts'
66

77
dotenv.config({ path: './playground/relay-kit/.env' })
88

9+
// Load environment variables from ./.env file
10+
// Follow .env-sample as an example to create your own file
911
const { PRIVATE_KEY, RPC_URL = '', CHAIN_ID = '', BUNDLER_URL = '' } = process.env
1012

1113
// PIM test token contract address

playground/relay-kit/userop-erc20-paymaster-counterfactual.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { privateKeyToAccount } from 'viem/accounts'
55

66
dotenv.config({ path: './playground/relay-kit/.env' })
77

8+
// Load environment variables from ./.env file
9+
// Follow .env-sample as an example to create your own file
810
const { PRIVATE_KEY, RPC_URL = '', CHAIN_ID = '', BUNDLER_URL = '' } = process.env
911

1012
// Paymaster addresses

playground/relay-kit/userop-erc20-paymaster.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { waitForOperationToFinish, setup4337Playground } from '../utils'
44

55
dotenv.config({ path: './playground/relay-kit/.env' })
66

7+
// Load environment variables from ./.env file
8+
// Follow .env-sample as an example to create your own file
79
const {
810
PRIVATE_KEY,
911
SAFE_ADDRESS = '0x',

playground/relay-kit/userop-parallel-execution.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { waitForOperationToFinish, setup4337Playground } from '../utils'
44

55
dotenv.config({ path: './playground/relay-kit/.env' })
66

7+
// Load environment variables from ./.env file
8+
// Follow .env-sample as an example to create your own file
79
const {
810
PRIVATE_KEY,
911
SAFE_ADDRESS = '0x',

playground/relay-kit/userop-verifying-paymaster-counterfactual.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { privateKeyToAccount } from 'viem/accounts'
55

66
dotenv.config({ path: './playground/relay-kit/.env' })
77

8+
// Load environment variables from ./.env file
9+
// Follow .env-sample as an example to create your own file
810
const {
911
PRIVATE_KEY,
1012
RPC_URL = '',

playground/relay-kit/userop-verifying-paymaster.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { setup4337Playground, waitForOperationToFinish } from '../utils'
44

55
dotenv.config({ path: './playground/relay-kit/.env' })
66

7+
// Load environment variables from ./.env file
8+
// Follow .env-sample as an example to create your own file
79
const {
810
PRIVATE_KEY,
911
SAFE_ADDRESS = '0x',

playground/relay-kit/userop.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { setup4337Playground, waitForOperationToFinish } from '../utils'
55

66
dotenv.config({ path: './playground/relay-kit/.env' })
77

8+
// Load environment variables from ./.env file
9+
// Follow .env-sample as an example to create your own file
810
const {
911
PRIVATE_KEY,
1012
SAFE_ADDRESS = '0x',

playground/sdk-starter-kit/owner-management.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { privateKeyToAddress } from 'viem/accounts'
55

66
dotenv.config({ path: './playground/sdk-starter-kit/.env' })
77

8+
// Load environment variables from ./.env file
9+
// Follow .env-sample as an example to create your own file
810
const {
911
OWNER_1_PRIVATE_KEY = '0x',
1012
OWNER_2_PRIVATE_KEY = '0x',

playground/sdk-starter-kit/send-off-chain-message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { SafeClientResult, createSafeClient, offChainMessages } from '@safe-glob
55

66
dotenv.config({ path: './playground/sdk-starter-kit/.env' })
77

8+
// Load environment variables from ./.env file
9+
// Follow .env-sample as an example to create your own file
810
const {
911
OWNER_1_PRIVATE_KEY = '0x',
1012
OWNER_2_PRIVATE_KEY = '0x',

playground/sdk-starter-kit/send-on-chain-message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { SafeClientResult, createSafeClient, onChainMessages } from '@safe-globa
55

66
dotenv.config({ path: './playground/sdk-starter-kit/.env' })
77

8+
// Load environment variables from ./.env file
9+
// Follow .env-sample as an example to create your own file
810
const {
911
OWNER_1_PRIVATE_KEY = '0x',
1012
OWNER_2_PRIVATE_KEY = '0x',

0 commit comments

Comments
 (0)