Skip to content

Commit

Permalink
Add .env config to playgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Feb 21, 2025
1 parent 7448632 commit 569b1f9
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 70 deletions.
16 changes: 16 additions & 0 deletions playground/sdk-starter-kit/.env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Safe config to create new Safes
OWNER_1_PRIVATE_KEY=
OWNER_2_PRIVATE_KEY=
OWNER_3_PRIVATE_KEY=
THRESHOLD=
SALT_NONCE=

# Rpc Url
RPC_URL=

# Safe address when the Safe already exists
SAFE_ADDRESS=

# Bundler
PAYMASTER_URL=
BUNDLER_URL=
23 changes: 16 additions & 7 deletions playground/sdk-starter-kit/owner-management.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import * as dotenv from 'dotenv'
import { Hex } from 'viem'
import { createSafeClient } from '@safe-global/sdk-starter-kit'
import { privateKeyToAddress } from 'viem/accounts'

const OWNER_1_PRIVATE_KEY = ''
const OWNER_2_PRIVATE_KEY = ''
const OWNER_2_ADDRESS = ''
dotenv.config({ path: './playground/sdk-starter-kit/.env' })

const RPC_URL = 'https://sepolia.gateway.tenderly.co'
const SAFE_ADDRESS = ''
const {
OWNER_1_PRIVATE_KEY = '0x',
OWNER_2_PRIVATE_KEY = '0x',
SAFE_ADDRESS = '0x',
RPC_URL = ''
} = process.env

async function addOwner() {
const safeClient = await createSafeClient({
Expand All @@ -14,8 +19,10 @@ async function addOwner() {
safeAddress: SAFE_ADDRESS
})

const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)

const transaction = await safeClient.createAddOwnerTransaction({
ownerAddress: OWNER_2_ADDRESS,
ownerAddress: owner2,
threshold: 2
})

Expand All @@ -37,8 +44,10 @@ async function removeOwner() {
safeAddress: SAFE_ADDRESS
})

const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)

const transaction = await safeClient1.createRemoveOwnerTransaction({
ownerAddress: OWNER_2_ADDRESS,
ownerAddress: owner2,
threshold: 1
})
const sendResult = await safeClient1.send({ transactions: [transaction] })
Expand Down
34 changes: 20 additions & 14 deletions playground/sdk-starter-kit/send-off-chain-message.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import * as dotenv from 'dotenv'
import { Hex } from 'viem'
import { privateKeyToAddress } from 'viem/accounts'
import { SafeClientResult, createSafeClient, offChainMessages } from '@safe-global/sdk-starter-kit'

const OWNER_1_PRIVATE_KEY = '0x'
const OWNER_2_PRIVATE_KEY = '0x'
const OWNER_3_PRIVATE_KEY = '0x'
dotenv.config({ path: './playground/sdk-starter-kit/.env' })

const THRESHOLD = 3
const SALT_NONCE = ''

const RPC_URL = 'https://rpc.sepolia.org'
const {
OWNER_1_PRIVATE_KEY = '0x',
OWNER_2_PRIVATE_KEY = '0x',
OWNER_3_PRIVATE_KEY = '0x',
RPC_URL = '',
THRESHOLD,
SALT_NONCE
} = process.env

const MESSAGE = "I'm the owner of this Safe"
// const MESSAGE = {
Expand Down Expand Up @@ -59,16 +63,16 @@ const MESSAGE = "I'm the owner of this Safe"
// }

async function send(): Promise<SafeClientResult> {
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY)
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY as Hex)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY as Hex)

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: OWNER_1_PRIVATE_KEY,
safeOptions: {
owners: [owner1, owner2, owner3],
threshold: THRESHOLD,
threshold: Number(THRESHOLD),
saltNonce: SALT_NONCE
}
})
Expand Down Expand Up @@ -124,18 +128,20 @@ async function confirm({ safeAddress, messages }: SafeClientResult, pk: string)
}

async function main() {
if (![1, 2, 3].includes(THRESHOLD)) {
const threshold = Number(THRESHOLD)

if (![1, 2, 3].includes(threshold)) {
return
}

const txResult = await send()

if (THRESHOLD > 1) {
if (threshold > 1) {
await confirm(txResult, OWNER_2_PRIVATE_KEY)
}

//@ts-ignore-next-line
if (THRESHOLD > 2) {
if (threshold > 2) {
await confirm(txResult, OWNER_3_PRIVATE_KEY)
}
}
Expand Down
32 changes: 19 additions & 13 deletions playground/sdk-starter-kit/send-on-chain-message.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as dotenv from 'dotenv'
import { Hex } from 'viem'
import { privateKeyToAddress } from 'viem/accounts'
import { SafeClientResult, createSafeClient, onChainMessages } from '@safe-global/sdk-starter-kit'

const OWNER_1_PRIVATE_KEY = '0x'
const OWNER_2_PRIVATE_KEY = '0x'
const OWNER_3_PRIVATE_KEY = '0x'
dotenv.config({ path: './playground/sdk-starter-kit/.env' })

const THRESHOLD = 3
const SALT_NONCE = ''
const {
OWNER_1_PRIVATE_KEY = '0x',
OWNER_2_PRIVATE_KEY = '0x',
OWNER_3_PRIVATE_KEY = '0x',
RPC_URL = '',
THRESHOLD,
SALT_NONCE
} = process.env

const RPC_URL = 'https://rpc.sepolia.org'
const MESSAGE = "I'm the owner of this Safe"
// const MESSAGE = {
// types: {
Expand Down Expand Up @@ -58,16 +63,16 @@ const MESSAGE = "I'm the owner of this Safe"
// }

async function send(): Promise<SafeClientResult> {
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY)
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY as Hex)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY as Hex)

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: OWNER_1_PRIVATE_KEY,
safeOptions: {
owners: [owner1, owner2, owner3],
threshold: THRESHOLD,
threshold: Number(THRESHOLD),
saltNonce: SALT_NONCE
}
})
Expand Down Expand Up @@ -119,18 +124,19 @@ async function confirm({ safeAddress, transactions }: SafeClientResult, pk: stri
}

async function main() {
if (![1, 2, 3].includes(THRESHOLD)) {
const threshold = Number(THRESHOLD)
if (![1, 2, 3].includes(threshold)) {
return
}

const txResult = await send()

if (THRESHOLD > 1) {
if (threshold > 1) {
await confirm(txResult, OWNER_2_PRIVATE_KEY)
}

//@ts-ignore-next-line
if (THRESHOLD > 2) {
if (threshold > 2) {
await confirm(txResult, OWNER_3_PRIVATE_KEY)
}
}
Expand Down
49 changes: 26 additions & 23 deletions playground/sdk-starter-kit/send-safe-operation.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import * as dotenv from 'dotenv'
import { privateKeyToAddress } from 'viem/accounts'
import { createPublicClient, http } from 'viem'
import { createPublicClient, Hex, http } from 'viem'
import { sepolia } from 'viem/chains'
import { SafeClientResult, createSafeClient, safeOperations } from '@safe-global/sdk-starter-kit'
import { generateTransferCallData } from '../utils'

const OWNER_1_PRIVATE_KEY = '0x'
const OWNER_2_PRIVATE_KEY = '0x'
const OWNER_3_PRIVATE_KEY = '0x'
dotenv.config({ path: './playground/sdk-starter-kit/.env' })

const THRESHOLD = 3
const SALT_NONCE = ''
const {
OWNER_1_PRIVATE_KEY = '0x',
OWNER_2_PRIVATE_KEY = '0x',
OWNER_3_PRIVATE_KEY = '0x',
RPC_URL = '',
THRESHOLD,
SALT_NONCE,
BUNDLER_URL = '',
PAYMASTER_URL = ''
} = process.env

const RPC_URL = 'https://rpc.sepolia.org'
const usdcTokenAddress = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' // SEPOLIA
const usdcAmount = 10_000n // 0.01 USDC

// Paymaster URL
const PIMLICO_API_KEY = ''
const PAYMASTER_URL = `https://api.pimlico.io/v2/sepolia/rpc?apikey=${PIMLICO_API_KEY}` // PIMLICO
const BUNDLER_URL = `https://api.pimlico.io/v2/sepolia/rpc?apikey=${PIMLICO_API_KEY}`

async function send(): Promise<SafeClientResult> {
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY)
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY as Hex)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY as Hex)

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: OWNER_1_PRIVATE_KEY,
safeOptions: {
owners: [owner1, owner2, owner3],
threshold: THRESHOLD,
threshold: Number(THRESHOLD),
saltNonce: SALT_NONCE
}
})
Expand Down Expand Up @@ -79,16 +80,16 @@ async function confirm(safeClientResult: SafeClientResult, pk: string) {
return
}

const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY)
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY as Hex)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY as Hex)

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: pk,
safeOptions: {
owners: [owner1, owner2, owner3],
threshold: THRESHOLD,
threshold: Number(THRESHOLD),
saltNonce: SALT_NONCE
}
})
Expand Down Expand Up @@ -117,18 +118,20 @@ async function confirm(safeClientResult: SafeClientResult, pk: string) {
}

async function main() {
if (![1, 2, 3].includes(THRESHOLD)) {
const threshold = Number(THRESHOLD)

if (![1, 2, 3].includes(threshold)) {
return
}

const safeOperationResult = await send()

if (THRESHOLD > 1) {
if (threshold > 1) {
await confirm(safeOperationResult, OWNER_2_PRIVATE_KEY)
}

//@ts-ignore-next-line
if (THRESHOLD > 2) {
if (threshold > 2) {
await confirm(safeOperationResult, OWNER_3_PRIVATE_KEY)
}
}
Expand Down
32 changes: 19 additions & 13 deletions playground/sdk-starter-kit/send-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import * as dotenv from 'dotenv'
import { Hex } from 'viem'
import { privateKeyToAddress } from 'viem/accounts'
import { SafeClientResult, createSafeClient } from '@safe-global/sdk-starter-kit'
import { generateTransferCallData } from '../utils'

const OWNER_1_PRIVATE_KEY = '0x'
const OWNER_2_PRIVATE_KEY = '0x'
const OWNER_3_PRIVATE_KEY = '0x'
dotenv.config({ path: './playground/sdk-starter-kit/.env' })

const THRESHOLD = 3
const SALT_NONCE = ''
const {
OWNER_1_PRIVATE_KEY = '0x',
OWNER_2_PRIVATE_KEY = '0x',
OWNER_3_PRIVATE_KEY = '0x',
RPC_URL = '',
THRESHOLD,
SALT_NONCE
} = process.env

const RPC_URL = 'https://rpc.sepolia.org'
const usdcTokenAddress = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' // SEPOLIA
const usdcAmount = 10_000n // 0.01 USDC

async function send(): Promise<SafeClientResult> {
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY)
const owner1 = privateKeyToAddress(OWNER_1_PRIVATE_KEY as Hex)
const owner2 = privateKeyToAddress(OWNER_2_PRIVATE_KEY as Hex)
const owner3 = privateKeyToAddress(OWNER_3_PRIVATE_KEY as Hex)

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: OWNER_1_PRIVATE_KEY,
safeOptions: {
owners: [owner1, owner2, owner3],
threshold: THRESHOLD,
threshold: Number(THRESHOLD),
saltNonce: SALT_NONCE
}
})
Expand Down Expand Up @@ -77,18 +82,19 @@ async function confirm({ safeAddress, transactions }: SafeClientResult, pk: stri
}

async function main() {
if (![1, 2, 3].includes(THRESHOLD)) {
const threshold = Number(THRESHOLD)
if (![1, 2, 3].includes(threshold)) {
return
}

const txResult = await send()

if (THRESHOLD > 1) {
if (threshold > 1) {
await confirm(txResult, OWNER_2_PRIVATE_KEY)
}

//@ts-ignore-next-line
if (THRESHOLD > 2) {
if (threshold > 2) {
await confirm(txResult, OWNER_3_PRIVATE_KEY)
}
}
Expand Down

0 comments on commit 569b1f9

Please sign in to comment.