@safe-global/protocol-kit 4.0.0-alpha.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +31 -988
- package/dist/src/Safe.d.ts +1 -16
- package/dist/src/Safe.js +71 -70
- package/dist/src/Safe.js.map +1 -1
- package/dist/src/SafeFactory.d.ts +1 -2
- package/dist/src/SafeFactory.js +31 -31
- package/dist/src/SafeFactory.js.map +1 -1
- package/dist/src/SafeProvider.js +2 -1
- package/dist/src/SafeProvider.js.map +1 -1
- package/dist/src/contracts/BaseContract.js +2 -2
- package/dist/src/contracts/BaseContract.js.map +1 -1
- package/dist/src/contracts/utils.d.ts +0 -1
- package/dist/src/contracts/utils.js +1 -5
- package/dist/src/contracts/utils.js.map +1 -1
- package/dist/src/managers/contractManager.d.ts +1 -2
- package/dist/src/managers/contractManager.js +53 -53
- package/dist/src/managers/contractManager.js.map +1 -1
- package/dist/src/managers/moduleManager.js +4 -4
- package/dist/src/managers/moduleManager.js.map +1 -1
- package/dist/src/managers/ownerManager.js +4 -4
- package/dist/src/managers/ownerManager.js.map +1 -1
- package/dist/src/utils/eip-3770/config.js +7 -0
- package/dist/src/utils/eip-3770/config.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
# Protocol Kit
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/%40safe-global%2Fprotocol-kit)
|
|
4
4
|
[](https://github.com/safe-global/safe-core-sdk/releases)
|
|
5
5
|
[](https://github.com/safe-global/safe-core-sdk/blob/main/LICENSE.md)
|
|
6
6
|
|
|
7
|
-
Software development kit that facilitates the interaction with
|
|
7
|
+
Software development kit that facilitates the interaction with [Safe Smart Accounts](https://github.com/safe-global/safe-smart-account) using a TypeScript interface. This Kit can be used to create new Safe accounts, update the configuration of existing Safes, create and execute transactions, among other features.
|
|
8
8
|
|
|
9
9
|
## Table of contents
|
|
10
10
|
|
|
11
|
+
- [Documentation](#documentation)
|
|
11
12
|
- [Installation](#installation)
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
- [Safe Factory API Reference](#factory-api)
|
|
16
|
-
- [Safe Core SDK API Reference](#sdk-api)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [Need Help or Have Questions?](#need-help-or-have-questions)
|
|
15
|
+
- [Contributing](#contributing)
|
|
17
16
|
- [License](#license)
|
|
18
|
-
- [Contributors](#contributors)
|
|
19
17
|
|
|
20
|
-
##
|
|
18
|
+
## Documentation
|
|
19
|
+
|
|
20
|
+
Head to the [Protocol Kit docs](https://docs.safe.global/sdk/protocol-kit) to learn more about how to use this SDK.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
21
23
|
|
|
22
24
|
Install the package with yarn or npm:
|
|
23
25
|
|
|
@@ -26,285 +28,24 @@ yarn add @safe-global/protocol-kit
|
|
|
26
28
|
npm install @safe-global/protocol-kit
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
##
|
|
30
|
-
|
|
31
|
-
Build the package with yarn or npm:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
yarn build
|
|
35
|
-
npm run build
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## <a name="tests">Tests</a>
|
|
39
|
-
|
|
40
|
-
Create a `.env` file with environment variables. You can use the `.env.example` file as a reference.
|
|
41
|
-
|
|
42
|
-
Test the package with yarn or npm:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
yarn test
|
|
46
|
-
npm run test
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## <a name="getting-started">Getting Started</a>
|
|
50
|
-
|
|
51
|
-
The following steps show how to set up the Protocol Kit, deploy a new Safe, create a Safe transaction, generate the required signatures from owners and execute the transaction. However, using the Protocol Kit 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 [Safe Web App](https://app.safe.global/), it is recommended that you follow this other [guide](/guides/integrating-the-safe-core-sdk.md) that covers the use of the Protocol Kit, combined with the API Kit.
|
|
52
|
-
|
|
53
|
-
### 1. Instantiate an EthAdapter
|
|
54
|
-
|
|
55
|
-
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.
|
|
56
|
-
|
|
57
|
-
Depending on the library used by the Dapp, there are two options:
|
|
58
|
-
|
|
59
|
-
- [Create an `EthersAdapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit/src/adapters/ethers)
|
|
60
|
-
- [Create a `Web3Adapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit/src/adapters/web3)
|
|
61
|
-
|
|
62
|
-
Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used in the SDK initialization.
|
|
63
|
-
|
|
64
|
-
### 2. Deploy a new Safe
|
|
65
|
-
|
|
66
|
-
To deploy a new Safe account instantiate the `SafeFactory` class and call the `deploySafe` method with the right params to configure the new Safe. This includes defining the list of owners and the threshold of the Safe. A Safe account with three owners and threshold equal three will be used as the starting point for this example but any Safe configuration is valid.
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
import Safe, { SafeFactory, SafeAccountConfig } from '@safe-global/protocol-kit'
|
|
70
|
-
|
|
71
|
-
const safeFactory = await SafeFactory.create({ ethAdapter })
|
|
72
|
-
|
|
73
|
-
const owners = ['0x<address>', '0x<address>', '0x<address>']
|
|
74
|
-
const threshold = 3
|
|
75
|
-
const safeAccountConfig: SafeAccountConfig = {
|
|
76
|
-
owners,
|
|
77
|
-
threshold
|
|
78
|
-
// ...
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const safeSdk: Safe = await safeFactory.deploySafe({ safeAccountConfig })
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
The `deploySafe` method executes a transaction from the `owner1` account, deploys a new Safe and returns an instance of the Protocol Kit connected to the new Safe. Check the `deploySafe` method in the [API Reference](#factory-api) for more details on additional configuration parameters and callbacks.
|
|
85
|
-
|
|
86
|
-
Call the `getAddress` method, for example, to check the address of the newly deployed Safe.
|
|
87
|
-
|
|
88
|
-
```js
|
|
89
|
-
const newSafeAddress = await safeSdk.getAddress()
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
To instantiate the Protocol Kit from an existing Safe just pass to it an instance of the `EthAdapter` class and the Safe address.
|
|
93
|
-
|
|
94
|
-
```js
|
|
95
|
-
import Safe from '@safe-global/protocol-kit'
|
|
96
|
-
|
|
97
|
-
const safeSdk: Safe = await Safe.create({ ethAdapter: ethAdapterOwner1, safeAddress })
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Check the `create` method in the [API Reference](#sdk-api) for more details on additional configuration parameters.
|
|
101
|
-
|
|
102
|
-
### 3. Create a Safe transaction
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
import { MetaTransactionData } from '@safe-global/safe-core-sdk-types'
|
|
106
|
-
|
|
107
|
-
const safeTransactionData: MetaTransactionData = {
|
|
108
|
-
to: '0x<address>',
|
|
109
|
-
value: '<eth_value_in_wei>',
|
|
110
|
-
data: '0x<data>'
|
|
111
|
-
}
|
|
112
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions: [safeTransactionData] })
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Check the `createTransaction` method in the [API Reference](#sdk-api) for additional details on creating MultiSend transactions.
|
|
116
|
-
|
|
117
|
-
Before executing this transaction, it must be signed by the owners and this can be done off-chain or on-chain. In this example `owner1` will sign it off-chain, `owner2` will sign it on-chain and `owner3` will execute it (the executor also signs the transaction transparently).
|
|
118
|
-
|
|
119
|
-
### 3.a. Off-chain signatures
|
|
120
|
-
|
|
121
|
-
The `owner1` account signs the transaction off-chain.
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction)
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Because the signature is off-chain, there is no interaction with the contract and the signature becomes available at `signedSafeTransaction.signatures`.
|
|
128
|
-
|
|
129
|
-
### 3.b. On-chain signatures
|
|
130
|
-
|
|
131
|
-
To connect `owner2` to the Safe we need to create a new instance of the class `EthAdapter` passing to its constructor the owner we would like to connect. After `owner2` account is connected to the SDK as a signer the transaction hash will be approved on-chain.
|
|
132
|
-
|
|
133
|
-
```js
|
|
134
|
-
const ethAdapterOwner2 = new EthersAdapter({ ethers, signerOrProvider: owner2 })
|
|
135
|
-
const safeSdk2 = await safeSdk.connect({ ethAdapter: ethAdapterOwner2, safeAddress })
|
|
136
|
-
const txHash = await safeSdk2.getTransactionHash(safeTransaction)
|
|
137
|
-
const approveTxResponse = await safeSdk2.approveTransactionHash(txHash)
|
|
138
|
-
await approveTxResponse.transactionResponse?.wait()
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### 4. Transaction execution
|
|
142
|
-
|
|
143
|
-
Lastly, `owner3` account is connected to the SDK as a signer and executor of the Safe transaction to execute it.
|
|
144
|
-
|
|
145
|
-
```js
|
|
146
|
-
const ethAdapterOwner3 = new EthersAdapter({ ethers, signerOrProvider: owner3 })
|
|
147
|
-
const safeSdk3 = await safeSdk2.connect({ ethAdapter: ethAdapterOwner3, safeAddress })
|
|
148
|
-
const executeTxResponse = await safeSdk3.executeTransaction(safeTransaction)
|
|
149
|
-
await executeTxResponse.transactionResponse?.wait()
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
All the signatures used to execute the transaction are now available at `safeTransaction.signatures`.
|
|
153
|
-
|
|
154
|
-
## <a name="factory-api">Safe Factory API Reference</a>
|
|
155
|
-
|
|
156
|
-
### create
|
|
157
|
-
|
|
158
|
-
Returns an instance of the Safe Factory.
|
|
159
|
-
|
|
160
|
-
```js
|
|
161
|
-
import { SafeFactory } from '@safe-global/protocol-kit'
|
|
162
|
-
|
|
163
|
-
const safeFactory = await SafeFactory.create({ ethAdapter })
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
- The `isL1SafeSingleton` flag
|
|
167
|
-
|
|
168
|
-
There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.
|
|
169
|
-
|
|
170
|
-
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeSingleton` flag to force the use of the `Safe.sol` contract.
|
|
171
|
-
|
|
172
|
-
```js
|
|
173
|
-
const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeSingleton: true })
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
- The `contractNetworks` property
|
|
177
|
-
|
|
178
|
-
If the Safe contracts are not deployed to your current network, the `contractNetworks` property will be required to point to the addresses of the Safe contracts previously deployed by you.
|
|
179
|
-
|
|
180
|
-
```js
|
|
181
|
-
import { ContractNetworksConfig } from '@safe-global/protocol-kit'
|
|
182
|
-
|
|
183
|
-
const chainId = await ethAdapter.getChainId()
|
|
184
|
-
const contractNetworks: ContractNetworksConfig = {
|
|
185
|
-
[chainId]: {
|
|
186
|
-
safeSingletonAddress: '<SINGLETON_ADDRESS>',
|
|
187
|
-
safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>',
|
|
188
|
-
multiSendAddress: '<MULTI_SEND_ADDRESS>',
|
|
189
|
-
multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>',
|
|
190
|
-
fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>',
|
|
191
|
-
signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>',
|
|
192
|
-
createCallAddress: '<CREATE_CALL_ADDRESS>',
|
|
193
|
-
simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>',
|
|
194
|
-
safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js
|
|
195
|
-
safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js
|
|
196
|
-
multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js
|
|
197
|
-
multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js
|
|
198
|
-
fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js
|
|
199
|
-
signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js
|
|
200
|
-
createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js
|
|
201
|
-
simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const safeFactory = await SafeFactory.create({ ethAdapter, contractNetworks })
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
- The `safeVersion` property
|
|
209
|
-
|
|
210
|
-
The `SafeFactory` constructor also accepts the `safeVersion` property to specify the Safe contract version that will be deployed. This string can take the values `1.0.0`, `1.1.1`, `1.2.0`, `1.3.0` or `1.4.1`. If not specified, the `DEFAULT_SAFE_VERSION` value will be used.
|
|
211
|
-
|
|
212
|
-
```js
|
|
213
|
-
const safeVersion = 'X.Y.Z'
|
|
214
|
-
const safeFactory = await SafeFactory.create({ ethAdapter, safeVersion })
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### deploySafe
|
|
218
|
-
|
|
219
|
-
Deploys a new Safe and returns an instance of the Protocol Kit connected to the deployed Safe. The Singleton address, contract version and layer instance (`Safe.sol` or `SafeL2.sol`) of the deployed Safe will depend on the configuration used to create the `safeFactory`.
|
|
220
|
-
|
|
221
|
-
```js
|
|
222
|
-
const safeAccountConfig: SafeAccountConfig = {
|
|
223
|
-
owners,
|
|
224
|
-
threshold,
|
|
225
|
-
to, // Optional
|
|
226
|
-
data, // Optional
|
|
227
|
-
fallbackHandler, // Optional
|
|
228
|
-
paymentToken, // Optional
|
|
229
|
-
payment, // Optional
|
|
230
|
-
paymentReceiver // Optional
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig })
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
This method can optionally receive the `saltNonce` parameter.
|
|
237
|
-
|
|
238
|
-
```js
|
|
239
|
-
const safeAccountConfig: SafeAccountConfig = {
|
|
240
|
-
owners,
|
|
241
|
-
threshold,
|
|
242
|
-
to, // Optional
|
|
243
|
-
data, // Optional
|
|
244
|
-
fallbackHandler, // Optional
|
|
245
|
-
paymentToken, // Optional
|
|
246
|
-
payment, // Optional
|
|
247
|
-
paymentReceiver // Optional
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const saltNonce = '<YOUR_CUSTOM_VALUE>'
|
|
251
|
-
|
|
252
|
-
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig, saltNonce })
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
Optionally, some properties can be passed as execution options:
|
|
256
|
-
|
|
257
|
-
```js
|
|
258
|
-
const options: Web3TransactionOptions = {
|
|
259
|
-
from, // Optional
|
|
260
|
-
gas, // Optional
|
|
261
|
-
gasPrice, // Optional
|
|
262
|
-
maxFeePerGas, // Optional
|
|
263
|
-
maxPriorityFeePerGas // Optional
|
|
264
|
-
nonce // Optional
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
```js
|
|
269
|
-
const options: EthersTransactionOptions = {
|
|
270
|
-
from, // Optional
|
|
271
|
-
gasLimit, // Optional
|
|
272
|
-
gasPrice, // Optional
|
|
273
|
-
maxFeePerGas, // Optional
|
|
274
|
-
maxPriorityFeePerGas // Optional
|
|
275
|
-
nonce // Optional
|
|
276
|
-
}
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
```js
|
|
280
|
-
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig, safeDeploymentConfig, options })
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
It can also take an optional callback which receives the `txHash` of the Safe deployment transaction prior to returning a new instance of the Protocol Kit:
|
|
284
|
-
|
|
285
|
-
```js
|
|
286
|
-
const callback = (txHash: string): void => {
|
|
287
|
-
console.log({ txHash })
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig, callback })
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
## <a name="sdk-api">Safe Core SDK API Reference</a>
|
|
294
|
-
|
|
295
|
-
### create
|
|
31
|
+
## Quick Start
|
|
296
32
|
|
|
297
|
-
|
|
33
|
+
- `provider`: You can set an EIP-1193 compatible provider or an HTTP/WebSocket RPC URL.
|
|
34
|
+
- `signer`: This is an optional parameter. It should be the provider's address you want to use or a private key. If not set, it will try to fetch a connected account from the provider.
|
|
298
35
|
|
|
299
|
-
|
|
36
|
+
Loading an already deployed Safe, using the `safeAddress` property:
|
|
300
37
|
|
|
301
38
|
```js
|
|
302
39
|
import Safe from '@safe-global/protocol-kit'
|
|
303
40
|
|
|
304
|
-
const
|
|
41
|
+
const protocolKit = await Safe.init({
|
|
42
|
+
provider,
|
|
43
|
+
signer,
|
|
44
|
+
safeAddress
|
|
45
|
+
})
|
|
305
46
|
```
|
|
306
47
|
|
|
307
|
-
Initialization of
|
|
48
|
+
Initialization of an undeployed Safe using the `predictedSafe` property. Because Safes are deployed in a deterministic way, passing a `predictedSafe` will allow to initialize the SDK with the Safe configuration and use it to some extent before it's deployed:
|
|
308
49
|
|
|
309
50
|
```js
|
|
310
51
|
import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit'
|
|
@@ -314,719 +55,21 @@ const predictedSafe: PredictedSafeProps = {
|
|
|
314
55
|
safeDeploymentConfig
|
|
315
56
|
}
|
|
316
57
|
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.
|
|
323
|
-
|
|
324
|
-
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeSingleton` flag to force the use of the `Safe.sol` contract.
|
|
325
|
-
|
|
326
|
-
```js
|
|
327
|
-
const safeSdk = await Safe.create({ ethAdapter, safeAddress, isL1SafeSingleton: true })
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
- The `contractNetworks` property
|
|
331
|
-
|
|
332
|
-
If the Safe contracts are not deployed to your current network, the `contractNetworks` property will be required to point to the addresses of the Safe contracts previously deployed by you.
|
|
333
|
-
|
|
334
|
-
```js
|
|
335
|
-
import { ContractNetworksConfig } from '@safe-global/protocol-kit'
|
|
336
|
-
|
|
337
|
-
const chainId = await ethAdapter.getChainId()
|
|
338
|
-
const contractNetworks: ContractNetworksConfig = {
|
|
339
|
-
[chainId]: {
|
|
340
|
-
safeSingletonAddress: '<SINGLETON_ADDRESS>',
|
|
341
|
-
safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>',
|
|
342
|
-
multiSendAddress: '<MULTI_SEND_ADDRESS>',
|
|
343
|
-
multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>',
|
|
344
|
-
fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>',
|
|
345
|
-
signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>',
|
|
346
|
-
createCallAddress: '<CREATE_CALL_ADDRESS>',
|
|
347
|
-
simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>',
|
|
348
|
-
safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js
|
|
349
|
-
safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js
|
|
350
|
-
multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js
|
|
351
|
-
multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js
|
|
352
|
-
fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js
|
|
353
|
-
signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js
|
|
354
|
-
createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js
|
|
355
|
-
simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const safeSdk = await Safe.create({ ethAdapter, safeAddress, contractNetworks })
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
### connect
|
|
363
|
-
|
|
364
|
-
Returns a new instance of the Protocol Kit connected to a new Safe or a new Signer. The new connected signer can be passed via the `ethAdapter` property while the new connected Safe can be passed using a `safeAddress` or a `predictedSafe`.
|
|
365
|
-
|
|
366
|
-
Connection of a deployed Safe using the `safeAddress` property:
|
|
367
|
-
|
|
368
|
-
```js
|
|
369
|
-
const safeSdk = await safeSdk.connect({ ethAdapter, safeAddress })
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
Connection of a not deployed Safe using the `predictedSafe` property. Because Safes are deployed in a deterministic way, passing a `predictedSafe` will allow to connect a Safe to the SDK with the Safe configuration:
|
|
373
|
-
|
|
374
|
-
```js
|
|
375
|
-
import { PredictedSafeProps } from '@safe-global/protocol-kit'
|
|
376
|
-
|
|
377
|
-
const predictedSafe: PredictedSafeProps = {
|
|
378
|
-
safeAccountConfig,
|
|
379
|
-
safeDeploymentConfig
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const safeSdk = await safeSdk.connect({ ethAdapter, predictedSafe })
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
- The `isL1SafeSingleton` flag
|
|
386
|
-
|
|
387
|
-
There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.
|
|
388
|
-
|
|
389
|
-
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeSingleton` flag to force the use of the `Safe.sol` contract.
|
|
390
|
-
|
|
391
|
-
```js
|
|
392
|
-
const safeSdk = await Safe.connect({ ethAdapter, safeAddress, isL1SafeSingleton: true })
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
- The `contractNetworks` property
|
|
396
|
-
|
|
397
|
-
If the Safe contracts are not deployed to your current network, the `contractNetworks` property will be required to point to the addresses of the Safe contracts previously deployed by you.
|
|
398
|
-
|
|
399
|
-
```js
|
|
400
|
-
import { ContractNetworksConfig } from '@safe-global/protocol-kit'
|
|
401
|
-
|
|
402
|
-
const chainId = await ethAdapter.getChainId()
|
|
403
|
-
const contractNetworks: ContractNetworksConfig = {
|
|
404
|
-
[chainId]: {
|
|
405
|
-
safeSingletonAddress: '<SINGLETON_ADDRESS>',
|
|
406
|
-
safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>',
|
|
407
|
-
multiSendAddress: '<MULTI_SEND_ADDRESS>',
|
|
408
|
-
multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>',
|
|
409
|
-
fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>',
|
|
410
|
-
signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>',
|
|
411
|
-
createCallAddress: '<CREATE_CALL_ADDRESS>',
|
|
412
|
-
simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>',
|
|
413
|
-
safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js
|
|
414
|
-
safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js
|
|
415
|
-
multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js
|
|
416
|
-
multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js
|
|
417
|
-
fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js
|
|
418
|
-
signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js
|
|
419
|
-
createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js
|
|
420
|
-
simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
const safeSdk = await Safe.connect({ ethAdapter, safeAddress, contractNetworks })
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
### getAddress
|
|
427
|
-
|
|
428
|
-
Returns the address of the current SafeProxy contract.
|
|
429
|
-
|
|
430
|
-
```js
|
|
431
|
-
const safeAddress = await safeSdk.getAddress()
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
### getContractVersion
|
|
435
|
-
|
|
436
|
-
Returns the Safe Singleton contract version.
|
|
437
|
-
|
|
438
|
-
```js
|
|
439
|
-
const contractVersion = await safeSdk.getContractVersion()
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
### getOwners
|
|
443
|
-
|
|
444
|
-
Returns the list of Safe owner accounts.
|
|
445
|
-
|
|
446
|
-
```js
|
|
447
|
-
const ownerAddresses = await safeSdk.getOwners()
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
### getNonce
|
|
451
|
-
|
|
452
|
-
Returns the Safe nonce.
|
|
453
|
-
|
|
454
|
-
```js
|
|
455
|
-
const nonce = await safeSdk.getNonce()
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
### getThreshold
|
|
459
|
-
|
|
460
|
-
Returns the Safe threshold.
|
|
461
|
-
|
|
462
|
-
```js
|
|
463
|
-
const threshold = await safeSdk.getThreshold()
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
### getChainId
|
|
467
|
-
|
|
468
|
-
Returns the chainId of the connected network.
|
|
469
|
-
|
|
470
|
-
```js
|
|
471
|
-
const chainId = await safeSdk.getChainId()
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
### getBalance
|
|
475
|
-
|
|
476
|
-
Returns the ETH balance of the Safe.
|
|
477
|
-
|
|
478
|
-
```js
|
|
479
|
-
const balance = await safeSdk.getBalance()
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
### getGuard
|
|
483
|
-
|
|
484
|
-
Returns the enabled Safe guard or 0x address if no guards are enabled.
|
|
485
|
-
|
|
486
|
-
```js
|
|
487
|
-
const guardAddress = await safeSdk.getGuard()
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
### getModules
|
|
491
|
-
|
|
492
|
-
Returns the list of addresses of all the enabled Safe modules.
|
|
493
|
-
|
|
494
|
-
```js
|
|
495
|
-
const moduleAddresses = await safeSdk.getModules()
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
### isModuleEnabled
|
|
499
|
-
|
|
500
|
-
Checks if a specific Safe module is enabled for the current Safe.
|
|
501
|
-
|
|
502
|
-
```js
|
|
503
|
-
const isEnabled = await safeSdk.isModuleEnabled(moduleAddress)
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
### isOwner
|
|
507
|
-
|
|
508
|
-
Checks if a specific address is an owner of the current Safe.
|
|
509
|
-
|
|
510
|
-
```js
|
|
511
|
-
const isOwner = await safeSdk.isOwner(address)
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### createTransaction
|
|
515
|
-
|
|
516
|
-
Returns a Safe transaction ready to be signed by the owners and executed. The Protocol Kit supports the creation of single Safe transactions but also MultiSend transactions.
|
|
517
|
-
|
|
518
|
-
This method takes an array of `MetaTransactionData` objects that represent the individual transactions we want to include in our MultiSend transaction.
|
|
519
|
-
|
|
520
|
-
When the array contains only one transaction, it is not wrapped in the MultiSend.
|
|
521
|
-
|
|
522
|
-
```js
|
|
523
|
-
const transactions: MetaTransactionData[] = [
|
|
524
|
-
{
|
|
525
|
-
to,
|
|
526
|
-
data,
|
|
527
|
-
value,
|
|
528
|
-
operation // Optional
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
to,
|
|
532
|
-
data,
|
|
533
|
-
value,
|
|
534
|
-
operation // Optional
|
|
535
|
-
}
|
|
536
|
-
// ...
|
|
537
|
-
]
|
|
538
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
This method can also receive the `options` parameter to set the optional properties in the MultiSend transaction:
|
|
542
|
-
|
|
543
|
-
```js
|
|
544
|
-
const transactions: MetaTransactionData[] = [
|
|
545
|
-
{
|
|
546
|
-
to,
|
|
547
|
-
data,
|
|
548
|
-
value,
|
|
549
|
-
operation // Optional
|
|
550
|
-
},
|
|
551
|
-
{
|
|
552
|
-
to,
|
|
553
|
-
data,
|
|
554
|
-
value,
|
|
555
|
-
operation // Optional
|
|
556
|
-
}
|
|
557
|
-
// ...
|
|
558
|
-
]
|
|
559
|
-
const options: SafeTransactionOptionalProps = {
|
|
560
|
-
safeTxGas, // Optional
|
|
561
|
-
baseGas, // Optional
|
|
562
|
-
gasPrice, // Optional
|
|
563
|
-
gasToken, // Optional
|
|
564
|
-
refundReceiver, // Optional
|
|
565
|
-
nonce // Optional
|
|
566
|
-
}
|
|
567
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions, options })
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
In addition, the optional `onlyCalls` parameter, which is `false` by default, allows to force the use of the `MultiSendCallOnly` instead of the `MultiSend` contract when sending a batch transaction:
|
|
571
|
-
|
|
572
|
-
```js
|
|
573
|
-
const onlyCalls = true
|
|
574
|
-
const safeTransaction = await safeSdk.createTransaction({
|
|
575
|
-
transactions,
|
|
576
|
-
options,
|
|
577
|
-
onlyCalls
|
|
58
|
+
const protocolKit = await Safe.init({
|
|
59
|
+
provider,
|
|
60
|
+
signer,
|
|
61
|
+
predictedSafe
|
|
578
62
|
})
|
|
579
63
|
```
|
|
580
64
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
- `operation`: `OperationType.Call` (0) is the default value.
|
|
584
|
-
- `safeTxGas`: The right gas estimation is the default value.
|
|
585
|
-
- `baseGas`: 0 is the default value.
|
|
586
|
-
- `gasPrice`: 0 is the default value.
|
|
587
|
-
- `gasToken`: 0x address is the default value.
|
|
588
|
-
- `refundReceiver`: 0x address is the default value.
|
|
589
|
-
- `nonce`: The current Safe nonce is the default value.
|
|
590
|
-
|
|
591
|
-
Read more about [create transactions from a Safe](https://docs.safe.global/safe-core-aa-sdk/protocol-kit#making-a-transaction-from-a-safe).
|
|
592
|
-
|
|
593
|
-
### createRejectionTransaction
|
|
594
|
-
|
|
595
|
-
Returns a Safe transaction ready to be signed by the owners that invalidates the pending Safe transaction/s with a specific nonce.
|
|
596
|
-
|
|
597
|
-
```js
|
|
598
|
-
const transactions: MetaTransactionData[] = [
|
|
599
|
-
{
|
|
600
|
-
// ...
|
|
601
|
-
}
|
|
602
|
-
]
|
|
603
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
604
|
-
const rejectionTransaction = await safeSdk.createRejectionTransaction(safeTransaction.data.nonce)
|
|
605
|
-
```
|
|
606
|
-
|
|
607
|
-
### copyTransaction
|
|
608
|
-
|
|
609
|
-
Copies a Safe transaction.
|
|
610
|
-
|
|
611
|
-
```js
|
|
612
|
-
const safeTransaction1 = await safeSdk.createTransaction({ transactions })
|
|
613
|
-
const safeTransaction2 = await copyTransaction(safeTransaction1)
|
|
614
|
-
```
|
|
615
|
-
|
|
616
|
-
### getTransactionHash
|
|
617
|
-
|
|
618
|
-
Returns the transaction hash of a Safe transaction.
|
|
619
|
-
|
|
620
|
-
```js
|
|
621
|
-
const transactions: MetaTransactionData[] = [
|
|
622
|
-
{
|
|
623
|
-
// ...
|
|
624
|
-
}
|
|
625
|
-
]
|
|
626
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
627
|
-
const txHash = await safeSdk.getTransactionHash(safeTransaction)
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
### signHash
|
|
631
|
-
|
|
632
|
-
Signs a hash using the current owner account.
|
|
633
|
-
|
|
634
|
-
```js
|
|
635
|
-
const transactions: MetaTransactionData[] = [
|
|
636
|
-
{
|
|
637
|
-
// ...
|
|
638
|
-
}
|
|
639
|
-
]
|
|
640
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
641
|
-
const txHash = await safeSdk.getTransactionHash(safeTransaction)
|
|
642
|
-
const signature = await safeSdk.signHash(txHash)
|
|
643
|
-
```
|
|
644
|
-
|
|
645
|
-
### signTypedData
|
|
646
|
-
|
|
647
|
-
Signs a transaction according to the EIP-712 using the current signer account.
|
|
648
|
-
|
|
649
|
-
```js
|
|
650
|
-
const transactions: MetaTransactionData[] = [
|
|
651
|
-
{
|
|
652
|
-
// ...
|
|
653
|
-
}
|
|
654
|
-
]
|
|
655
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
656
|
-
const signature = await safeSdk.signTypedData(safeTransaction)
|
|
657
|
-
```
|
|
658
|
-
|
|
659
|
-
### signTransaction
|
|
660
|
-
|
|
661
|
-
Returns a new `SafeTransaction` object that includes the signature of the current owner. `eth_sign` will be used by default to generate the signature.
|
|
662
|
-
|
|
663
|
-
```js
|
|
664
|
-
const transactions: MetaTransactionData[] = [
|
|
665
|
-
{
|
|
666
|
-
// ...
|
|
667
|
-
}
|
|
668
|
-
]
|
|
669
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
670
|
-
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction)
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
Optionally, an additional parameter can be passed to specify a different way of signing:
|
|
674
|
-
|
|
675
|
-
```js
|
|
676
|
-
const signedSafeTransaction = await safeSdk.signTransaction(
|
|
677
|
-
safeTransaction,
|
|
678
|
-
SigningMethod.ETH_SIGN_TYPED_DATA
|
|
679
|
-
)
|
|
680
|
-
```
|
|
681
|
-
|
|
682
|
-
```js
|
|
683
|
-
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction, SigningMethod.ETH_SIGN) // default option.
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
### approveTransactionHash
|
|
687
|
-
|
|
688
|
-
Approves a hash on-chain using the current owner account.
|
|
689
|
-
|
|
690
|
-
```js
|
|
691
|
-
const transactions: MetaTransactionData[] = [
|
|
692
|
-
{
|
|
693
|
-
// ...
|
|
694
|
-
}
|
|
695
|
-
]
|
|
696
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
697
|
-
const txHash = await safeSdk.getTransactionHash(safeTransaction)
|
|
698
|
-
const txResponse = await safeSdk.approveTransactionHash(txHash)
|
|
699
|
-
await txResponse.transactionResponse?.wait()
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
Optionally, some properties can be passed as execution options:
|
|
703
|
-
|
|
704
|
-
```js
|
|
705
|
-
const options: Web3TransactionOptions = {
|
|
706
|
-
from, // Optional
|
|
707
|
-
gas, // Optional
|
|
708
|
-
gasPrice, // Optional
|
|
709
|
-
maxFeePerGas, // Optional
|
|
710
|
-
maxPriorityFeePerGas // Optional
|
|
711
|
-
nonce // Optional
|
|
712
|
-
}
|
|
713
|
-
```
|
|
714
|
-
|
|
715
|
-
```js
|
|
716
|
-
const options: EthersTransactionOptions = {
|
|
717
|
-
from, // Optional
|
|
718
|
-
gasLimit, // Optional
|
|
719
|
-
gasPrice, // Optional
|
|
720
|
-
maxFeePerGas, // Optional
|
|
721
|
-
maxPriorityFeePerGas // Optional
|
|
722
|
-
nonce // Optional
|
|
723
|
-
}
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
```js
|
|
727
|
-
const txResponse = await safeSdk.approveTransactionHash(txHash, options)
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
### getOwnersWhoApprovedTx
|
|
731
|
-
|
|
732
|
-
Returns a list of owners who have approved a specific Safe transaction.
|
|
733
|
-
|
|
734
|
-
```js
|
|
735
|
-
const transactions: MetaTransactionData[] = [
|
|
736
|
-
{
|
|
737
|
-
// ...
|
|
738
|
-
}
|
|
739
|
-
]
|
|
740
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
741
|
-
const txHash = await safeSdk.getTransactionHash(safeTransaction)
|
|
742
|
-
const ownerAddresses = await safeSdk.getOwnersWhoApprovedTx(txHash)
|
|
743
|
-
```
|
|
744
|
-
|
|
745
|
-
### createEnableFallbackHandlerTx
|
|
746
|
-
|
|
747
|
-
Returns the Safe transaction to enable the fallback handler.
|
|
748
|
-
|
|
749
|
-
```js
|
|
750
|
-
const safeTransaction = await safeSdk.createEnableFallbackHandlerTx(fallbackHandlerAddress)
|
|
751
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
752
|
-
await txResponse.transactionResponse?.wait()
|
|
753
|
-
```
|
|
754
|
-
|
|
755
|
-
This method can optionally receive the `options` parameter:
|
|
756
|
-
|
|
757
|
-
```js
|
|
758
|
-
const options: SafeTransactionOptionalProps = {
|
|
759
|
-
safeTxGas, // Optional
|
|
760
|
-
baseGas, // Optional
|
|
761
|
-
gasPrice, // Optional
|
|
762
|
-
gasToken, // Optional
|
|
763
|
-
refundReceiver, // Optional
|
|
764
|
-
nonce // Optional
|
|
765
|
-
}
|
|
766
|
-
const safeTransaction = await safeSdk.createEnableFallbackHandlerTx(fallbackHandlerAddress, options)
|
|
767
|
-
```
|
|
768
|
-
|
|
769
|
-
### createDisableFallbackHandlerTx
|
|
770
|
-
|
|
771
|
-
Returns the Safe transaction to disable the fallback handler.
|
|
772
|
-
|
|
773
|
-
```js
|
|
774
|
-
const safeTransaction = await safeSdk.createDisableFallbackHandlerTx()
|
|
775
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
776
|
-
await txResponse.transactionResponse?.wait()
|
|
777
|
-
```
|
|
778
|
-
|
|
779
|
-
This method can optionally receive the `options` parameter:
|
|
780
|
-
|
|
781
|
-
```js
|
|
782
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
783
|
-
const safeTransaction = await safeSdk.createDisableFallbackHandlerTx(options)
|
|
784
|
-
```
|
|
785
|
-
|
|
786
|
-
### createEnableGuardTx
|
|
787
|
-
|
|
788
|
-
Returns the Safe transaction to enable a Safe guard.
|
|
789
|
-
|
|
790
|
-
```js
|
|
791
|
-
const safeTransaction = await safeSdk.createEnableGuardTx(guardAddress)
|
|
792
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
793
|
-
await txResponse.transactionResponse?.wait()
|
|
794
|
-
```
|
|
795
|
-
|
|
796
|
-
This method can optionally receive the `options` parameter:
|
|
65
|
+
## Need Help or Have Questions?
|
|
797
66
|
|
|
798
|
-
|
|
799
|
-
const options: SafeTransactionOptionalProps = {
|
|
800
|
-
safeTxGas, // Optional
|
|
801
|
-
baseGas, // Optional
|
|
802
|
-
gasPrice, // Optional
|
|
803
|
-
gasToken, // Optional
|
|
804
|
-
refundReceiver, // Optional
|
|
805
|
-
nonce // Optional
|
|
806
|
-
}
|
|
807
|
-
const safeTransaction = await safeSdk.createEnableGuardTx(guardAddress, options)
|
|
808
|
-
```
|
|
809
|
-
|
|
810
|
-
### createDisableGuardTx
|
|
811
|
-
|
|
812
|
-
Returns the Safe transaction to disable a Safe guard.
|
|
813
|
-
|
|
814
|
-
```js
|
|
815
|
-
const safeTransaction = await safeSdk.createDisableGuardTx()
|
|
816
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
817
|
-
await txResponse.transactionResponse?.wait()
|
|
818
|
-
```
|
|
819
|
-
|
|
820
|
-
This method can optionally receive the `options` parameter:
|
|
821
|
-
|
|
822
|
-
```js
|
|
823
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
824
|
-
const safeTransaction = await safeSdk.createDisableGuardTx(options)
|
|
825
|
-
```
|
|
826
|
-
|
|
827
|
-
### createEnableModuleTx
|
|
828
|
-
|
|
829
|
-
Returns a Safe transaction ready to be signed that will enable a Safe module.
|
|
830
|
-
|
|
831
|
-
```js
|
|
832
|
-
const safeTransaction = await safeSdk.createEnableModuleTx(moduleAddress)
|
|
833
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
834
|
-
await txResponse.transactionResponse?.wait()
|
|
835
|
-
```
|
|
836
|
-
|
|
837
|
-
This method can optionally receive the `options` parameter:
|
|
838
|
-
|
|
839
|
-
```js
|
|
840
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
841
|
-
const safeTransaction = await safeSdk.createEnableModuleTx(moduleAddress, options)
|
|
842
|
-
```
|
|
843
|
-
|
|
844
|
-
### createDisableModuleTx
|
|
845
|
-
|
|
846
|
-
Returns a Safe transaction ready to be signed that will disable a Safe module.
|
|
847
|
-
|
|
848
|
-
```js
|
|
849
|
-
const safeTransaction = await safeSdk.createDisableModuleTx(moduleAddress)
|
|
850
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
851
|
-
await txResponse.transactionResponse?.wait()
|
|
852
|
-
```
|
|
853
|
-
|
|
854
|
-
This method can optionally receive the `options` parameter:
|
|
855
|
-
|
|
856
|
-
```js
|
|
857
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
858
|
-
const safeTransaction = await safeSdk.createDisableModuleTx(moduleAddress, options)
|
|
859
|
-
```
|
|
860
|
-
|
|
861
|
-
### createAddOwnerTx
|
|
862
|
-
|
|
863
|
-
Returns the Safe transaction to add an owner and optionally change the threshold.
|
|
864
|
-
|
|
865
|
-
```js
|
|
866
|
-
const params: AddOwnerTxParams = {
|
|
867
|
-
ownerAddress,
|
|
868
|
-
threshold // Optional. If `threshold` is not provided the current threshold will not change.
|
|
869
|
-
}
|
|
870
|
-
const safeTransaction = await safeSdk.createAddOwnerTx(params)
|
|
871
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
872
|
-
await txResponse.transactionResponse?.wait()
|
|
873
|
-
```
|
|
874
|
-
|
|
875
|
-
This method can optionally receive the `options` parameter:
|
|
876
|
-
|
|
877
|
-
```js
|
|
878
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
879
|
-
const safeTransaction = await safeSdk.createAddOwnerTx(params, options)
|
|
880
|
-
```
|
|
881
|
-
|
|
882
|
-
### createRemoveOwnerTx
|
|
883
|
-
|
|
884
|
-
Returns the Safe transaction to remove an owner and optionally change the threshold.
|
|
885
|
-
|
|
886
|
-
```js
|
|
887
|
-
const params: RemoveOwnerTxParams = {
|
|
888
|
-
ownerAddress,
|
|
889
|
-
newThreshold // Optional. If `newThreshold` is not provided, the current threshold will be decreased by one.
|
|
890
|
-
}
|
|
891
|
-
const safeTransaction = await safeSdk.createRemoveOwnerTx(params)
|
|
892
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
893
|
-
await txResponse.transactionResponse?.wait()
|
|
894
|
-
```
|
|
895
|
-
|
|
896
|
-
This method can optionally receive the `options` parameter:
|
|
897
|
-
|
|
898
|
-
```js
|
|
899
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
900
|
-
const safeTransaction = await safeSdk.createRemoveOwnerTx(params, options)
|
|
901
|
-
```
|
|
902
|
-
|
|
903
|
-
### createSwapOwnerTx
|
|
904
|
-
|
|
905
|
-
Returns the Safe transaction to replace an owner of the Safe with a new one.
|
|
906
|
-
|
|
907
|
-
```js
|
|
908
|
-
const params: SwapOwnerTxParams = {
|
|
909
|
-
oldOwnerAddress,
|
|
910
|
-
newOwnerAddress
|
|
911
|
-
}
|
|
912
|
-
const safeTransaction = await safeSdk.createSwapOwnerTx(params)
|
|
913
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
914
|
-
await txResponse.transactionResponse?.wait()
|
|
915
|
-
```
|
|
916
|
-
|
|
917
|
-
This method can optionally receive the `options` parameter:
|
|
918
|
-
|
|
919
|
-
```js
|
|
920
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
921
|
-
const safeTransaction = await safeSdk.createSwapOwnerTx(params, options)
|
|
922
|
-
```
|
|
923
|
-
|
|
924
|
-
### createChangeThresholdTx
|
|
925
|
-
|
|
926
|
-
Returns the Safe transaction to change the threshold.
|
|
927
|
-
|
|
928
|
-
```js
|
|
929
|
-
const safeTransaction = await safeSdk.createChangeThresholdTx(newThreshold)
|
|
930
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
931
|
-
await txResponse.transactionResponse?.wait()
|
|
932
|
-
```
|
|
933
|
-
|
|
934
|
-
This method can optionally receive the `options` parameter:
|
|
935
|
-
|
|
936
|
-
```js
|
|
937
|
-
const options: SafeTransactionOptionalProps = { ... }
|
|
938
|
-
const safeTransaction = await safeSdk.createChangeThresholdTx(newThreshold, options)
|
|
939
|
-
```
|
|
940
|
-
|
|
941
|
-
### isValidTransaction
|
|
942
|
-
|
|
943
|
-
Checks if a Safe transaction can be executed successfully with no errors.
|
|
944
|
-
|
|
945
|
-
```js
|
|
946
|
-
const transactions: MetaTransactionData[] = [
|
|
947
|
-
{
|
|
948
|
-
// ...
|
|
949
|
-
}
|
|
950
|
-
]
|
|
951
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
952
|
-
const isValidTx = await safeSdk.isValidTransaction(safeTransaction)
|
|
953
|
-
```
|
|
954
|
-
|
|
955
|
-
Optionally, some properties can be passed as execution options:
|
|
956
|
-
|
|
957
|
-
```js
|
|
958
|
-
const options: Web3TransactionOptions = {
|
|
959
|
-
from, // Optional
|
|
960
|
-
gas, // Optional
|
|
961
|
-
gasPrice, // Optional
|
|
962
|
-
maxFeePerGas, // Optional
|
|
963
|
-
maxPriorityFeePerGas // Optional
|
|
964
|
-
nonce // Optional
|
|
965
|
-
}
|
|
966
|
-
```
|
|
967
|
-
|
|
968
|
-
```js
|
|
969
|
-
const options: EthersTransactionOptions = {
|
|
970
|
-
from, // Optional
|
|
971
|
-
gasLimit, // Optional
|
|
972
|
-
gasPrice, // Optional
|
|
973
|
-
maxFeePerGas, // Optional
|
|
974
|
-
maxPriorityFeePerGas // Optional
|
|
975
|
-
nonce // Optional
|
|
976
|
-
}
|
|
977
|
-
```
|
|
978
|
-
|
|
979
|
-
```js
|
|
980
|
-
const isValidTx = await safeSdk.isValidTransaction(safeTransaction, options)
|
|
981
|
-
```
|
|
982
|
-
|
|
983
|
-
### executeTransaction
|
|
984
|
-
|
|
985
|
-
Executes a Safe transaction.
|
|
986
|
-
|
|
987
|
-
```js
|
|
988
|
-
const transactions: MetaTransactionData[] = [
|
|
989
|
-
{
|
|
990
|
-
// ...
|
|
991
|
-
}
|
|
992
|
-
]
|
|
993
|
-
const safeTransaction = await safeSdk.createTransaction({ transactions })
|
|
994
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction)
|
|
995
|
-
await txResponse.transactionResponse?.wait()
|
|
996
|
-
```
|
|
997
|
-
|
|
998
|
-
Optionally, some properties can be passed as execution options:
|
|
999
|
-
|
|
1000
|
-
```js
|
|
1001
|
-
const options: Web3TransactionOptions = {
|
|
1002
|
-
from, // Optional
|
|
1003
|
-
gas, // Optional
|
|
1004
|
-
gasPrice, // Optional
|
|
1005
|
-
maxFeePerGas, // Optional
|
|
1006
|
-
maxPriorityFeePerGas // Optional
|
|
1007
|
-
nonce // Optional
|
|
1008
|
-
}
|
|
1009
|
-
```
|
|
1010
|
-
|
|
1011
|
-
```js
|
|
1012
|
-
const options: EthersTransactionOptions = {
|
|
1013
|
-
from, // Optional
|
|
1014
|
-
gasLimit, // Optional
|
|
1015
|
-
gasPrice, // Optional
|
|
1016
|
-
maxFeePerGas, // Optional
|
|
1017
|
-
maxPriorityFeePerGas // Optional
|
|
1018
|
-
nonce // Optional
|
|
1019
|
-
}
|
|
1020
|
-
```
|
|
1021
|
-
|
|
1022
|
-
```js
|
|
1023
|
-
const txResponse = await safeSdk.executeTransaction(safeTransaction, options)
|
|
1024
|
-
```
|
|
67
|
+
If you have any doubts, questions, or need assistance, feel free to reach out! [Here you will find how to get support.](https://github.com/safe-global/safe-core-sdk/tree/main/SUPPORT.md)
|
|
1025
68
|
|
|
1026
|
-
##
|
|
69
|
+
## Contributing
|
|
1027
70
|
|
|
1028
|
-
|
|
71
|
+
Please read our [contribution guidelines](https://github.com/safe-global/safe-core-sdk/tree/main/CONTRIBUTING.md) before submitting any changes. We appreciate your help! 🙌
|
|
1029
72
|
|
|
1030
|
-
##
|
|
73
|
+
## License
|
|
1031
74
|
|
|
1032
|
-
|
|
75
|
+
This library is [released under MIT](https://github.com/safe-global/safe-core-sdk/blob/main/LICENSE.md).
|