Skip to content

Commit

Permalink
Merge pull request #257 from safe-global/playground
Browse files Browse the repository at this point in the history
Add an SDK playground
  • Loading branch information
germartinez authored Sep 6, 2022
2 parents 3cfaa01 + f0461b7 commit a0fefbf
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Software developer tools that facilitate the interaction with the Gnosis Safe [c

| Title | Description |
| ------- | ----------- |
| [Integrating the Safe Core SDK](https://github.com/safe-global/safe-core-sdk/blob/main/packages/guides/integrating-the-safe-core-sdk.md) | This guide shows how to use the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk) and [Safe Service Client](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-service-client). |
| [Integrating the Safe Core SDK](https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md) | This guide shows how to use the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk) and [Safe Service Client](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-service-client). |

## Packages

Expand All @@ -19,3 +19,13 @@ Software developer tools that facilitate the interaction with the Gnosis Safe [c
[safe-web3-lib](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-web3-lib) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-web3-lib.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-web3-lib) | Web3.js utilities and Safe contracts types (typechain web3-v1) used to initialize the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk) |
[safe-service-client](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-service-client) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-service-client.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-service-client) | [Safe Transaction Service API](https://github.com/safe-global/safe-transaction-service) client library |
[safe-ethers-adapters](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-ethers-adapters) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-adapters.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-adapters) | [Ethers](https://docs.ethers.io/v5/single-page/) adapter that facilitates the interaction with the [Gnosis Safe Services](https://github.com/safe-global/safe-transaction-service) |

## Playground

There is a [playground script](https://github.com/safe-global/safe-core-sdk/tree/main/playground/index.ts) that can be used to play around with the Safe Core SDK.

Update the config inside the script and execute the following command to run the script:

```bash
yarn play
```
2 changes: 1 addition & 1 deletion packages/guides/README.md → guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ We'll assume that you are familiar with TypeScript (JavaScript), Ethereum and ha

If you need help, you can reach Gnosis Safe developers in the #safe-developers channel at https://chat.gnosis.io/ or create a discussion at https://github.com/safe-global/safe-core-sdk/discussions.

Let's jump into the guide: [Integrating the Safe Core SDK](/packages/guides/integrating-the-safe-core-sdk.md)
Let's jump into the guide: [Integrating the Safe Core SDK](/guides/integrating-the-safe-core-sdk.md)
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "lerna run build --stream --npm-client=yarn",
"test": "FORCE_COLOR=1 lerna run test --stream --npm-client=yarn",
"test:ci": "FORCE_COLOR=1 lerna run test:ci --stream --npm-client=yarn",
"play": "ts-node ./playground",
"format": "lerna run format --npm-client=yarn",
"postinstall": "cd packages/safe-ethers-lib; hardhat compile"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-core-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ npm build

## <a name="getting-started">Getting Started</a>

The following steps show how to set up the Safe Core SDK, deploy a new Safe, create a Safe transaction, generate the required signatures from owners and execute the transaction. However, using the Safe Core SDK alone will not allow for the collection of owner signatures off-chain. To do this and be able to see and confirm the pending transactions shown in the [Gnosis Safe Web App](https://gnosis-safe.io/app/), it is recommended that you follow this other [guide](/packages/guides/integrating-the-safe-core-sdk.md) that covers the use of the Safe Core SDK, combined with the Safe Service Client.
The following steps show how to set up the Safe Core SDK, deploy a new Safe, create a Safe transaction, generate the required signatures from owners and execute the transaction. However, using the Safe Core SDK alone will not allow for the collection of owner signatures off-chain. To do this and be able to see and confirm the pending transactions shown in the [Gnosis Safe Web App](https://gnosis-safe.io/app/), it is recommended that you follow this other [guide](/guides/integrating-the-safe-core-sdk.md) that covers the use of the Safe Core SDK, combined with the Safe Service Client.

### 1. Instantiate an EthAdapter

Expand Down
63 changes: 63 additions & 0 deletions playground/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import Safe, { SafeFactory } from '@gnosis.pm/safe-core-sdk'
import EthersAdapter from '@gnosis.pm/safe-ethers-lib'
import SafeServiceClient from '@gnosis.pm/safe-service-client'
import { ethers } from 'ethers'

// This file can be used to play around with the Safe Core SDK

const config = {
RPC_URL: 'https://goerli.infura.io/v3/<INFURA_TOKEN>',
SAFE_ADDRESS: '<SAFE_ADDRESS>',
SAFE_OWNERS_PRIVATE_KEYS: [
'<OWNER_1_PRIVATE_KEY>',
'<OWNER_2_PRIVATE_KEY>',
// ...
],
SAFE_TRANSACTION_SERVICE_URL: '<SAFE_TRANSACTION_SERVICE_URL>'
}

async function main() {
console.log('<<< SAFE CORE SDK PLAYGROUND >>>')

const provider = new ethers.providers.JsonRpcProvider(config.RPC_URL)
const signers = config.SAFE_OWNERS_PRIVATE_KEYS.map(
(privateKey) => new ethers.Wallet(privateKey, provider)
)

// Display Safe info
const owners = await Promise.all(signers.map(async (signer) => await signer.getAddress()))
console.log('SAFE_OWNERS:', owners.toString())

// Select the signer that will be connected to the Core SDK
const currentSignerIndex = 0
const currentSigner = signers[currentSignerIndex]

// EthAdapter instance
const ethAdapter = new EthersAdapter({
ethers,
signer: currentSigner
})

// Safe Core SDK instance
const safe = await Safe.create({
ethAdapter,
safeAddress: config.SAFE_ADDRESS
})

// SafeFactory instance
const safeFactory = SafeFactory.create({ ethAdapter })

// Safe Service Client instance
const safeService = new SafeServiceClient({
txServiceUrl: config.SAFE_TRANSACTION_SERVICE_URL,
ethAdapter
})

// Deploy new Safes?
// Propose transactions?
// Sign transactions?
// Execute transactions?
// And much more...
}

main()

0 comments on commit a0fefbf

Please sign in to comment.