Skip to content

Commit

Permalink
update ethers docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniSomoza committed Oct 27, 2023
1 parent 4e9e445 commit 2f9a285
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@safe-global/relay-kit": "^1.0.0",
"@safe-global/safe-core-sdk-types": "^2.0.0",
"dotenv": "^16.0.3",
"ethers": "5.7.2"
"ethers": "^6.8.0"
}
}
10 changes: 5 additions & 5 deletions examples/protocol-kit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ethers } from 'ethers'

// https://chainlist.org/?search=goerli&testnets=true
const RPC_URL = 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161'
const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.JsonRpcProvider(RPC_URL)

// Initialize signers

Expand Down Expand Up @@ -74,7 +74,7 @@ async function initalizeSafe(existingAddress = EXISTING_SAFE_ADDRESS) {

async function depositToSafe(depositSigner = owner1Signer, amount = '0.01') {

const safeAmount = ethers.utils.parseUnits(amount, 'ether').toHexString()
const safeAmount = ethers.parseUnits(amount, 'ether').toHexString()

const transactionParameters = {
to: safeAddress,
Expand All @@ -91,7 +91,7 @@ async function proposeTransaction(withdrawAmount = '0.005',
destination = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') {

// Create a transaction object
withdrawAmount = ethers.utils.parseUnits(withdrawAmount, 'ether').toString()
withdrawAmount = ethers.parseUnits(withdrawAmount, 'ether').toString()

const safeTransactionData: SafeTransactionDataPartial = {
to: destination,
Expand Down Expand Up @@ -145,7 +145,7 @@ async function executeTransaction(safeTxHash: string, safeSdk: Safe = safeSdkOwn

let safeBalance = await safeSdk.getBalance()

console.log(`[Before Transaction] Safe Balance: ${ethers.utils.formatUnits(safeBalance, 'ether')} ETH`)
console.log(`[Before Transaction] Safe Balance: ${ethers.formatUnits(safeBalance, 'ether')} ETH`)

const safeTransaction = await safeService.getTransaction(safeTxHash)
const executeTxResponse = await safeSdk.executeTransaction(safeTransaction)
Expand All @@ -156,7 +156,7 @@ async function executeTransaction(safeTxHash: string, safeSdk: Safe = safeSdkOwn

safeBalance = await safeSdk.getBalance()

console.log(`[After Transaction] Safe Balance: ${ethers.utils.formatUnits(safeBalance, 'ether')} ETH`)
console.log(`[After Transaction] Safe Balance: ${ethers.formatUnits(safeBalance, 'ether')} ETH`)
}

async function main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/relay-kit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { MetaTransactionData, MetaTransactionOptions, OperationType, RelayTransa
// Customize the following variables
// https://chainlist.org
const RPC_URL = 'https://endpoints.omniatech.io/v1/bsc/mainnet/public'
const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.JsonRpcProvider(RPC_URL)
const signer = new ethers.Wallet(process.env.OWNER_1_PRIVATE_KEY!, provider)
const safeAddress = '0x6651FD6Abe0843f7B6CB9047b89655cc7Aa78221' // Safe from which the transaction will be sent. Replace with your Safe address
const chainId = 56

// Any address can be used for destination. In this example, we use vitalik.eth
const destinationAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
const withdrawAmount = ethers.utils.parseUnits('0.0005', 'ether').toString()
const withdrawAmount = ethers.parseUnits('0.0005', 'ether').toString()

// Get Gelato Relay API Key: https://relay.gelato.network/
const GELATO_RELAY_API_KEY = process.env.GELATO_RELAY_API_KEY!
Expand Down
50 changes: 50 additions & 0 deletions examples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@adraffy/[email protected]":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz#d2a39395c587e092d77cbbc80acf956a54f38bf7"
integrity sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==

"@ethereumjs/[email protected]":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@ethereumjs/common/-/common-2.5.0.tgz#ec61551b31bef7a69d1dc634d8932468866a4268"
Expand Down Expand Up @@ -376,6 +381,18 @@
axios "0.24.0"
ethers "5.7.2"

"@noble/[email protected]":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
dependencies:
"@noble/hashes" "1.3.2"

"@noble/[email protected]":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@safe-global/api-kit@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@safe-global/api-kit/-/api-kit-1.1.0.tgz#b46bcb4491d43576832488183019769d37e3f3e6"
Expand Down Expand Up @@ -481,6 +498,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.1.0.tgz#258805edc37c327cf706e64c6957f241ca4c4c20"
integrity sha512-O+z53uwx64xY7D6roOi4+jApDGFg0qn6WHcxe5QeqjMaTezBO/mxdfFXIVAVVyNWKx84OmPB3L8kbVYOTeN34A==

"@types/[email protected]":
version "18.15.13"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.13.tgz#f64277c341150c979e42b00e4ac289290c9df469"
integrity sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==

"@types/node@^12.12.6":
version "12.20.55"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"
Expand Down Expand Up @@ -525,6 +547,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.0.0.tgz#e21df10ad6c2053295bcbb8dab40b09dbea87e4d"
integrity sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw==

[email protected]:
version "4.0.0-beta.5"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-4.0.0-beta.5.tgz#8d2452c52adedebc3a3e28465d858c11ca315873"
integrity sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==

ajv@^6.12.3:
version "6.12.6"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
Expand Down Expand Up @@ -1149,6 +1176,19 @@ [email protected], ethers@^5.7.2:
"@ethersproject/web" "5.7.1"
"@ethersproject/wordlists" "5.7.0"

ethers@^6.8.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.8.0.tgz#0a26f57e96fd697cefcfcef464e0c325689d1daf"
integrity sha512-zrFbmQRlraM+cU5mE4CZTLBurZTs2gdp2ld0nG/f3ecBK+x6lZ69KSxBqZ4NjclxwfTxl5LeNufcBbMsTdY53Q==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@types/node" "18.15.13"
aes-js "4.0.0-beta.5"
tslib "2.4.0"
ws "8.5.0"

[email protected]:
version "0.1.6"
resolved "https://registry.yarnpkg.com/ethjs-unit/-/ethjs-unit-0.1.6.tgz#c665921e476e87bce2a9d588a6fe0405b2c41699"
Expand Down Expand Up @@ -2323,6 +2363,11 @@ tr46@~0.0.3:
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

[email protected]:
version "2.4.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==

tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
Expand Down Expand Up @@ -2725,6 +2770,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c"
integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==

[email protected]:
version "8.5.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f"
integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==

ws@^3.0.0:
version "3.3.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-3.3.3.tgz#f1cf84fe2d5e901ebce94efaece785f187a228f2"
Expand Down
2 changes: 1 addition & 1 deletion reference/safe-core-sdk/auth-kit/AuthKitBasePack.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Provides a mechanism to connect to the provider services and returns an Ethereum

Disconnects the provider services and cleans up any data related to the current user.

### `getProvider(): web3Provider`
### `getProvider(): BrowserProvider`

Returns a Web3 provider that can be used to interact with the blockchain (`web3.js` or `ethers.js` for example).

Expand Down
2 changes: 1 addition & 1 deletion reference/safe-core-sdk/auth-kit/Web3AuthModalPack.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ await web3AuthModalPack.init(web3AuthModalOptions, adapters, modalConfig)
// Sign in
const { eoa, safes } = await web3AuthModalPack.signIn()
const userInfo = await web3AuthModalPack.getUserInfo()
const web3Provider = web3AuthModalPack.getProvider()
const BrowserProvider = web3AuthModalPack.getProvider()

// Subscribe to events
const handler = (event) => {}
Expand Down
4 changes: 2 additions & 2 deletions safe-core-sdk/api-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ yarn add @safe-global/api-kit

## Instantiate an EthAdapter

First of all, we need to create an `EthAdapter`, which contains all the required utilities for the SDKs to interact with the blockchain. It acts as a wrapper for [web3.js](https://web3js.readthedocs.io/) or [ethers.js](https://docs.ethers.io/v5/) Ethereum libraries.
First of all, we need to create an `EthAdapter`, which contains all the required utilities for the SDKs to interact with the blockchain. It acts as a wrapper for [web3.js](https://web3js.readthedocs.io/) or [ethers.js](https://docs.ethers.org/v6/) Ethereum libraries.

Check warning on line 27 in safe-core-sdk/api-kit/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] safe-core-sdk/api-kit/README.md#L27

[Microsoft.We] Try to avoid using first-person plural like 'we'.
Raw output
{"message": "[Microsoft.We] Try to avoid using first-person plural like 'we'.", "location": {"path": "safe-core-sdk/api-kit/README.md", "range": {"start": {"line": 27, "column": 15}}}, "severity": "WARNING"}

Check notice on line 27 in safe-core-sdk/api-kit/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] safe-core-sdk/api-kit/README.md#L27

[Microsoft.ComplexWords] Consider using 'has' instead of 'contains'.
Raw output
{"message": "[Microsoft.ComplexWords] Consider using 'has' instead of 'contains'.", "location": {"path": "safe-core-sdk/api-kit/README.md", "range": {"start": {"line": 27, "column": 56}}}, "severity": "INFO"}

Depending on the library used by the Dapp, there are two options:

Expand All @@ -36,7 +36,7 @@ Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used
```typescript
import { EthersAdapter } from '@safe-global/protocol-kit'

const provider = new ethers.providers.JsonRpcProvider(config.RPC_URL)
const provider = new ethers.JsonRpcProvider(config.RPC_URL)
const signer = new ethers.Wallet(config.SIGNER_ADDRESS_PRIVATE_KEY, provider)

const ethAdapter = new EthersAdapter({
Expand Down
6 changes: 3 additions & 3 deletions safe-core-sdk/auth-kit/web3auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Once connected, you can use any of the methods available in the [Protocol Kit](h
import { ethers } from 'ethers'
import { EthersAdapter } from '@safe-global/protocol-kit'

provider = new ethers.providers.Web3Provider(web3AuthModalPack.getProvider())
provider = new ethers.BrowserProvider(web3AuthModalPack.getProvider())
signer = provider.getSigner()

const ethAdapter = new EthersAdapter({
Expand All @@ -162,7 +162,7 @@ const safeSDK = await Safe.create({
const safeTransactionData: MetaTransactionData = {
to: '0x',
data: '0x',
value: ethers.utils.parseUnits('0.0001', 'ether').toString()
value: ethers.parseUnits('0.0001', 'ether').toString()
}

const safeTransaction = await safeSDK.createTransaction({ safeTransactionData })
Expand All @@ -183,7 +183,7 @@ const address = '0x...'
await web3.eth.personal.sign(message, address)

// Using ethers
const provider = new ethers.providers.Web3Provider(web3AuthModalPack.getProvider())
const provider = new ethers.BrowserProvider(web3AuthModalPack.getProvider())
const signer = provider.getSigner()

await signer.sendTransaction(tx)
Expand Down
12 changes: 6 additions & 6 deletions safe-core-sdk/protocol-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ First, we'll need to install some dependences from `safe-core-sdk` and the `ethe

To interact with Ethereum and other EVM blockchains in Node, we can either use: web3.js or ethers.js. In this tutorial, we'll use the ethers.js library. To use `web3js`, see [Instantiate an EthAdapter section in Guide: Integrating the Safe Core SDK](https://github.com/safe-global/safe-core-sdk/blob/main/guides/integrating-the-safe-core-sdk.md#instantiate-an-ethadapter).

The Protocol Kit is compatible with ethers v4 and v5, not the latest v6 version so make sure you specify this when installing the SDK.
The Protocol Kit is compatible only with ethers v6. Make sure you specify this version when installing the SDK.

Check notice on line 22 in safe-core-sdk/protocol-kit/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] safe-core-sdk/protocol-kit/README.md#L22

[write-good.E-Prime] Try to avoid using 'is'.
Raw output
{"message": "[write-good.E-Prime] Try to avoid using 'is'.", "location": {"path": "safe-core-sdk/protocol-kit/README.md", "range": {"start": {"line": 22, "column": 18}}}, "severity": "INFO"}

Check warning on line 22 in safe-core-sdk/protocol-kit/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] safe-core-sdk/protocol-kit/README.md#L22

[write-good.Weasel] 'only' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'only' is a weasel word!", "location": {"path": "safe-core-sdk/protocol-kit/README.md", "range": {"start": {"line": 22, "column": 32}}}, "severity": "WARNING"}

You can store your environment variables such as private keys in a `.env` file. To read easily from `.env` files, use the `dotenv` library.

```bash
yarn add ethers@5.7.2 @safe-global/protocol-kit \
yarn add ethers @safe-global/protocol-kit \
@safe-global/api-kit \
@safe-global/safe-core-sdk-types \
dotenv
Expand Down Expand Up @@ -73,7 +73,7 @@ dotenv.config()

// https://chainlist.org/?search=goerli&testnets=true
const RPC_URL='https://eth-goerli.public.blastapi.io'
const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.JsonRpcProvider(RPC_URL)

// Initialize signers
const owner1Signer = new ethers.Wallet(process.env.OWNER_1_PRIVATE_KEY!, provider)
Expand Down Expand Up @@ -146,7 +146,7 @@ You will send some ETH to this Safe.
```tsx
const safeAddress = safeSdk.getAddress()

const safeAmount = ethers.utils.parseUnits('0.01', 'ether').toHexString()
const safeAmount = ethers.parseUnits('0.01', 'ether').toHexString()

const transactionParameters = {
to: safeAddress,
Expand Down Expand Up @@ -191,7 +191,7 @@ import { SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types'

// Any address can be used. In this example you will use vitalik.eth
const destination = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
const amount = ethers.utils.parseUnits('0.005', 'ether').toString()
const amount = ethers.parseUnits('0.005', 'ether').toString()

const safeTransactionData: SafeTransactionDataPartial = {
to: destination,
Expand Down Expand Up @@ -275,7 +275,7 @@ You know that the transaction was executed if the balance in your Safe changes.
```tsx
const afterBalance = await safeSdk.getBalance()

console.log(`The final balance of the Safe: ${ethers.utils.formatUnits(afterBalance, 'ether')} ETH`)
console.log(`The final balance of the Safe: ${ethers.formatUnits(afterBalance, 'ether')} ETH`)
```

```bash
Expand Down
8 changes: 4 additions & 4 deletions safe-core-sdk/relay-kit/gelato.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Modify the variables to customize to match your desired transaction settings.
```typescript
// https://chainlist.org
const RPC_URL='https://endpoints.omniatech.io/v1/bsc/mainnet/public'
const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.JsonRpcProvider(RPC_URL)
const signer = new ethers.Wallet(process.env.OWNER_1_PRIVATE_KEY!, provider)
const safeAddress = '0x...' // Safe from which the transaction will be sent

// Any address can be used for destination. In this example, we use vitalik.eth
const destinationAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
const withdrawAmount = ethers.utils.parseUnits('0.005', 'ether').toString()
const withdrawAmount = ethers.parseUnits('0.005', 'ether').toString()
```

### Create the transaction object
Expand Down Expand Up @@ -143,13 +143,13 @@ Modify the variables to customize to match your desired transaction settings.
```typescript
// https://chainlist.org
const RPC_URL='https://endpoints.omniatech.io/v1/bsc/mainnet/public'
const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.JsonRpcProvider(RPC_URL)
const signer = new ethers.Wallet(process.env.OWNER_1_PRIVATE_KEY!, provider)
const safeAddress = '0x...' // Safe from which the transaction will be sent

// Any address can be used for destination. In this example, we use vitalik.eth
const destinationAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
const withdrawAmount = ethers.utils.parseUnits('0.005', 'ether').toString()
const withdrawAmount = ethers.parseUnits('0.005', 'ether').toString()
```

### Create the transaction object
Expand Down
4 changes: 2 additions & 2 deletions safe-smart-account/signatures/eip-1271.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The Safe contracts and interface support off-chain [EIP-1271](https://eips.ethereum.org/EIPS/eip-1271) signatures. However, because Safe is a smart account, the flow is slightly different from simple EOA signatures.

This doc explains signing and verifying messages off-chain. All examples use [WalletConnect](https://walletconnect.com/) to connect to the Safe and [ethers](https://ethers.io).
This doc explains signing and verifying messages off-chain. All examples use [WalletConnect](https://walletconnect.com/) to connect to the Safe and [ethers](https://docs.ethers.org/).

## Signing messages

Expand All @@ -29,7 +29,7 @@ As Safe{Wallet} is a multi signature wallet, this process can take some time bec
#### Example: sign message

```typescript
import { hashMessage, hexlify, toUtf8Bytes } from 'ethers/lib/utils'
import { hashMessage, hexlify, toUtf8Bytes } from 'ethers'

const signMessage = async (message: string) => {
const hexMessage = hexlify(toUtf8Bytes(message))
Expand Down

0 comments on commit 2f9a285

Please sign in to comment.