@safe-global/protocol-kit 0.1.1 → 1.0.0

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