@safe-global/api-kit 1.3.0 → 2.0.0-alpha.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.
package/LICENSE.md CHANGED
@@ -1,9 +1,9 @@
1
- MIT License
2
-
3
- Copyright (c) 2021-2023 Safe Ecosystem Foundation
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2023 Safe Ecosystem Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,323 +1,313 @@
1
- # Safe API Kit
2
-
3
- [![NPM Version](https://badge.fury.io/js/%40safe-global%2Fapi-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fapi-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 Transaction Service API](https://github.com/safe-global/safe-transaction-service).
8
-
9
- ## Table of contents
10
-
11
- - [Installation](#installation)
12
- - [Build](#build)
13
- - [Tests](#tests)
14
- - [Initialization](#initialization)
15
- - [API Reference](#api-reference)
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 run build
35
- ```
36
-
37
- ## <a name="tests">Tests</a>
38
-
39
- Create a `.env` file with environment variables. You can use the `.env.example` file as a reference.
40
-
41
- Test the package with yarn or npm:
42
-
43
- ```bash
44
- yarn test
45
- npm run test
46
- ```
47
-
48
- ## <a name="initialization">Initialization</a>
49
-
50
- ### Instantiate an EthAdapter
51
-
52
- 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.
53
-
54
- Depending on the library used by the Dapp, there are two options:
55
-
56
- - [Create an `EthersAdapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit/src/adapters/ethers)
57
- - [Create a `Web3Adapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit/src/adapters/web3)
58
-
59
- Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used in the SDK initialization.
60
-
61
- ### Initialize the SafeApiKit
62
-
63
- ```js
64
- import SafeApiKit from '@safe-global/api-kit'
65
-
66
- const safeService = new SafeApiKit({
67
- txServiceUrl: 'https://safe-transaction-mainnet.safe.global',
68
- ethAdapter
69
- })
70
- ```
71
-
72
- ## <a name="api-reference">API Reference</a>
73
-
74
- ### getServiceInfo
75
-
76
- Returns the information and configuration of the service.
77
-
78
- ```js
79
- const serviceInfo: SafeServiceInfoResponse = await safeService.getServiceInfo()
80
- ```
81
-
82
- ### getServiceMasterCopiesInfo
83
-
84
- Returns the list of Safe master copies.
85
-
86
- ```js
87
- const masterCopies: MasterCopyResponse = await safeService.getServiceMasterCopiesInfo()
88
- ```
89
-
90
- ### decodeData
91
-
92
- Decodes the specified Safe transaction data.
93
-
94
- ```js
95
- const decodedData = await safeService.decodeData(data)
96
- ```
97
-
98
- ### getSafesByOwner
99
-
100
- Returns the list of Safes where the address provided is an owner.
101
-
102
- ```js
103
- const safes: OwnerResponse = await safeService.getSafesByOwner(ownerAddress)
104
- ```
105
-
106
- ### getSafesByModule
107
-
108
- Returns the list of Safes where the module address provided is enabled.
109
-
110
- ```js
111
- const safes: ModulesResponse = await getSafesByModule(moduleAddress)
112
- ```
113
-
114
- ### getTransaction
115
-
116
- Returns all the information of a Safe transaction.
117
-
118
- ```js
119
- const tx: SafeMultisigTransactionResponse = await safeService.getTransaction(safeTxHash)
120
- ```
121
-
122
- ### getTransactionConfirmations
123
-
124
- Returns the list of confirmations for a given a Safe transaction.
125
-
126
- ```js
127
- const confirmations: SafeMultisigConfirmationListResponse =
128
- await safeService.getTransactionConfirmations(safeTxHash)
129
- ```
130
-
131
- ### confirmTransaction
132
-
133
- Adds a confirmation for a Safe transaction.
134
-
135
- ```js
136
- const signature: SignatureResponse = await safeService.confirmTransaction(safeTxHash, signature)
137
- ```
138
-
139
- ### getSafeInfo
140
-
141
- Returns the information and configuration of the provided Safe address.
142
-
143
- ```js
144
- const safeInfo: SafeInfoResponse = await safeService.getSafeInfo(safeAddress)
145
- ```
146
-
147
- ### getSafeDelegates
148
-
149
- Returns the list of delegates for a given Safe address.
150
-
151
- ```js
152
- const delegateConfig: GetSafeDelegateProps = {
153
- safeAddress, // Optional
154
- delegateAddress, // Optional
155
- delegatorAddress, // Optional
156
- label, // Optional
157
- limit, // Optional
158
- offset // Optional
159
- }
160
- const delegates: SafeDelegateListResponse = await safeService.getSafeDelegates(delegateConfig)
161
- ```
162
-
163
- ### addSafeDelegate
164
-
165
- Adds a new delegate for a given Safe address.
166
-
167
- ```js
168
- const delegateConfig: AddSafeDelegateProps = {
169
- safeAddress, // Optional
170
- delegateAddress,
171
- delegatorAddress,
172
- label,
173
- signer
174
- }
175
- await safeService.addSafeDelegate(delegateConfig)
176
- ```
177
-
178
- ### removeSafeDelegate
179
-
180
- Removes a delegate for a given Safe address.
181
-
182
- ```js
183
- const delegateConfig: DeleteSafeDelegateProps = {
184
- delegateAddress,
185
- delegatorAddress,
186
- signer
187
- }
188
- await safeService.removeSafeDelegate(delegateConfig)
189
- ```
190
-
191
- ### getSafeCreationInfo
192
-
193
- Returns the creation information of a Safe.
194
-
195
- ```js
196
- const safeCreationInfo: SafeCreationInfoResponse = await safeService.getSafeCreationInfo(
197
- safeAddress
198
- )
199
- ```
200
-
201
- ### estimateSafeTransaction
202
-
203
- Estimates the safeTxGas for a given Safe multi-signature transaction.
204
-
205
- ```js
206
- const estimateTx: SafeMultisigTransactionEstimateResponse =
207
- await safeService.estimateSafeTransaction(safeAddress, safeTransaction)
208
- ```
209
-
210
- ### proposeTransaction
211
-
212
- Creates a new multi-signature transaction and stores it in the Safe Transaction Service.
213
-
214
- ```js
215
- const transactionConfig: ProposeTransactionProps = {
216
- safeAddress,
217
- safeTxHash,
218
- safeTransactionData,
219
- senderAddress,
220
- senderSignature,
221
- origin
222
- }
223
- await safeService.proposeTransaction(transactionConfig)
224
- ```
225
-
226
- ### getIncomingTransactions
227
-
228
- Returns the history of incoming transactions of a Safe account.
229
-
230
- ```js
231
- const incomingTxs: TransferListResponse = await safeService.getIncomingTransactions(safeAddress)
232
- ```
233
-
234
- ### getModuleTransactions
235
-
236
- Returns the history of module transactions of a Safe account.
237
-
238
- ```js
239
- const moduleTxs: SafeModuleTransactionListResponse = await safeService.getModuleTransactions(
240
- safeAddress
241
- )
242
- ```
243
-
244
- ### getMultisigTransactions
245
-
246
- Returns the history of multi-signature transactions of a Safe account.
247
-
248
- ```js
249
- const multisigTxs: SafeMultisigTransactionListResponse = await safeService.getMultisigTransactions(
250
- safeAddress
251
- )
252
- ```
253
-
254
- ### getPendingTransactions
255
-
256
- Returns the list of multi-signature transactions that are waiting for the confirmation of the Safe owners.
257
-
258
- ```js
259
- const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
260
- safeAddress
261
- )
262
- ```
263
-
264
- ```js
265
- const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
266
- safeAddress,
267
- currentNonce
268
- )
269
- ```
270
-
271
- ### getAllTransactions
272
-
273
- Returns a list of transactions for a Safe. The list has different structures depending on the transaction type.
274
-
275
- ```js
276
- const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
277
- safeAddress
278
- )
279
- ```
280
-
281
- ```js
282
- const allTxsOptions: AllTransactionsOptions = {
283
- executed,
284
- queued,
285
- trusted
286
- }
287
- const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
288
- safeAddress,
289
- allTxsOptions
290
- )
291
- ```
292
-
293
- ### getNextNonce
294
-
295
- Returns the right nonce to propose a new transaction right after the last pending transaction.
296
-
297
- ```js
298
- const nextNonce = await safeService.getNextNonce(safeAddress)
299
- ```
300
-
301
- ### getTokenList
302
-
303
- Returns the list of all the ERC20 tokens handled by the Safe.
304
-
305
- ```js
306
- const tokens: TokenInfoListResponse = await safeService.getTokenList()
307
- ```
308
-
309
- ### getToken
310
-
311
- Returns the information of a given ERC20 token.
312
-
313
- ```js
314
- const token: TokenInfoResponse = await safeService.getToken(tokenAddress)
315
- ```
316
-
317
- ## <a name="license">License</a>
318
-
319
- This library is released under MIT.
320
-
321
- ## <a name="contributors">Contributors</a>
322
-
323
- - Germán Martínez ([germartinez](https://github.com/germartinez))
1
+ # Safe API Kit
2
+
3
+ [![NPM Version](https://badge.fury.io/js/%40safe-global%2Fapi-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fapi-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 Transaction Service API](https://github.com/safe-global/safe-transaction-service).
8
+
9
+ ## Table of contents
10
+
11
+ - [Installation](#installation)
12
+ - [Build](#build)
13
+ - [Tests](#tests)
14
+ - [Initialization](#initialization)
15
+ - [API Reference](#api-reference)
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 run build
35
+ ```
36
+
37
+ ## <a name="tests">Tests</a>
38
+
39
+ Create a `.env` file with environment variables. You can use the `.env.example` file as a reference.
40
+
41
+ Test the package with yarn or npm:
42
+
43
+ ```bash
44
+ yarn test
45
+ npm run test
46
+ ```
47
+
48
+ ## <a name="initialization">Initialization</a>
49
+
50
+ ### Initialize the SafeApiKit
51
+
52
+ ```js
53
+ import SafeApiKit from '@safe-global/api-kit'
54
+
55
+ const safeService = new SafeApiKit({
56
+ chainId: 1n,
57
+ // Optional. txServiceUrl must be used to set a custom service. For example on chains where Safe doesn't run services.
58
+ txServiceUrl: 'https://safe-transaction-mainnet.safe.global'
59
+ })
60
+ ```
61
+
62
+ ## <a name="api-reference">API Reference</a>
63
+
64
+ ### getServiceInfo
65
+
66
+ Returns the information and configuration of the service.
67
+
68
+ ```js
69
+ const serviceInfo: SafeServiceInfoResponse = await safeService.getServiceInfo()
70
+ ```
71
+
72
+ ### getServiceSingletonsInfo
73
+
74
+ Returns the list of Safe singleton copies.
75
+
76
+ ```js
77
+ const singletons: SafeSingletonResponse = await safeService.getServiceSingletonsInfo()
78
+ ```
79
+
80
+ ### decodeData
81
+
82
+ Decodes the specified Safe transaction data.
83
+
84
+ ```js
85
+ const decodedData = await safeService.decodeData(data)
86
+ ```
87
+
88
+ ### getSafesByOwner
89
+
90
+ Returns the list of Safes where the address provided is an owner.
91
+
92
+ ```js
93
+ const safes: OwnerResponse = await safeService.getSafesByOwner(ownerAddress)
94
+ ```
95
+
96
+ ### getSafesByModule
97
+
98
+ Returns the list of Safes where the module address provided is enabled.
99
+
100
+ ```js
101
+ const safes: ModulesResponse = await getSafesByModule(moduleAddress)
102
+ ```
103
+
104
+ ### getTransaction
105
+
106
+ Returns all the information of a Safe transaction.
107
+
108
+ ```js
109
+ const tx: SafeMultisigTransactionResponse = await safeService.getTransaction(safeTxHash)
110
+ ```
111
+
112
+ ### getTransactionConfirmations
113
+
114
+ Returns the list of confirmations for a given a Safe transaction.
115
+
116
+ ```js
117
+ const confirmations: SafeMultisigConfirmationListResponse =
118
+ await safeService.getTransactionConfirmations(safeTxHash)
119
+ ```
120
+
121
+ ### confirmTransaction
122
+
123
+ Adds a confirmation for a Safe transaction.
124
+
125
+ ```js
126
+ const signature: SignatureResponse = await safeService.confirmTransaction(safeTxHash, signature)
127
+ ```
128
+
129
+ ### getSafeInfo
130
+
131
+ Returns the information and configuration of the provided Safe address.
132
+
133
+ ```js
134
+ const safeInfo: SafeInfoResponse = await safeService.getSafeInfo(safeAddress)
135
+ ```
136
+
137
+ ### getSafeDelegates
138
+
139
+ Returns the list of delegates for a given Safe address.
140
+
141
+ ```js
142
+ const delegateConfig: GetSafeDelegateProps = {
143
+ safeAddress, // Optional
144
+ delegateAddress, // Optional
145
+ delegatorAddress, // Optional
146
+ label, // Optional
147
+ limit, // Optional
148
+ offset // Optional
149
+ }
150
+ const delegates: SafeDelegateListResponse = await safeService.getSafeDelegates(delegateConfig)
151
+ ```
152
+
153
+ ### addSafeDelegate
154
+
155
+ Adds a new delegate for a given Safe address.
156
+
157
+ ```js
158
+ const delegateConfig: AddSafeDelegateProps = {
159
+ safeAddress, // Optional
160
+ delegateAddress,
161
+ delegatorAddress,
162
+ label,
163
+ signer
164
+ }
165
+ await safeService.addSafeDelegate(delegateConfig)
166
+ ```
167
+
168
+ ### removeSafeDelegate
169
+
170
+ Removes a delegate for a given Safe address.
171
+
172
+ ```js
173
+ const delegateConfig: DeleteSafeDelegateProps = {
174
+ delegateAddress,
175
+ delegatorAddress,
176
+ signer
177
+ }
178
+ await safeService.removeSafeDelegate(delegateConfig)
179
+ ```
180
+
181
+ ### getSafeCreationInfo
182
+
183
+ Returns the creation information of a Safe.
184
+
185
+ ```js
186
+ const safeCreationInfo: SafeCreationInfoResponse = await safeService.getSafeCreationInfo(
187
+ safeAddress
188
+ )
189
+ ```
190
+
191
+ ### estimateSafeTransaction
192
+
193
+ Estimates the safeTxGas for a given Safe multi-signature transaction.
194
+
195
+ ```js
196
+ const estimateTx: SafeMultisigTransactionEstimateResponse =
197
+ await safeService.estimateSafeTransaction(safeAddress, safeTransaction)
198
+ ```
199
+
200
+ ### proposeTransaction
201
+
202
+ Creates a new multi-signature transaction and stores it in the Safe Transaction Service.
203
+
204
+ ```js
205
+ const transactionConfig: ProposeTransactionProps = {
206
+ safeAddress,
207
+ safeTxHash,
208
+ safeTransactionData,
209
+ senderAddress,
210
+ senderSignature,
211
+ origin
212
+ }
213
+ await safeService.proposeTransaction(transactionConfig)
214
+ ```
215
+
216
+ ### getIncomingTransactions
217
+
218
+ Returns the history of incoming transactions of a Safe account.
219
+
220
+ ```js
221
+ const incomingTxs: TransferListResponse = await safeService.getIncomingTransactions(safeAddress)
222
+ ```
223
+
224
+ ### getModuleTransactions
225
+
226
+ Returns the history of module transactions of a Safe account.
227
+
228
+ ```js
229
+ const moduleTxs: SafeModuleTransactionListResponse = await safeService.getModuleTransactions(
230
+ safeAddress
231
+ )
232
+ ```
233
+
234
+ ### getMultisigTransactions
235
+
236
+ Returns the history of multi-signature transactions of a Safe account.
237
+
238
+ ```js
239
+ const multisigTxs: SafeMultisigTransactionListResponse = await safeService.getMultisigTransactions(
240
+ safeAddress
241
+ )
242
+ ```
243
+
244
+ ### getPendingTransactions
245
+
246
+ Returns the list of multi-signature transactions that are waiting for the confirmation of the Safe owners.
247
+
248
+ ```js
249
+ const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
250
+ safeAddress
251
+ )
252
+ ```
253
+
254
+ ```js
255
+ const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
256
+ safeAddress,
257
+ currentNonce
258
+ )
259
+ ```
260
+
261
+ ### getAllTransactions
262
+
263
+ Returns a list of transactions for a Safe. The list has different structures depending on the transaction type.
264
+
265
+ ```js
266
+ const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
267
+ safeAddress
268
+ )
269
+ ```
270
+
271
+ ```js
272
+ const allTxsOptions: AllTransactionsOptions = {
273
+ executed,
274
+ queued,
275
+ trusted
276
+ }
277
+ const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
278
+ safeAddress,
279
+ allTxsOptions
280
+ )
281
+ ```
282
+
283
+ ### getNextNonce
284
+
285
+ Returns the right nonce to propose a new transaction right after the last pending transaction.
286
+
287
+ ```js
288
+ const nextNonce = await safeService.getNextNonce(safeAddress)
289
+ ```
290
+
291
+ ### getTokenList
292
+
293
+ Returns the list of all the ERC20 tokens handled by the Safe.
294
+
295
+ ```js
296
+ const tokens: TokenInfoListResponse = await safeService.getTokenList()
297
+ ```
298
+
299
+ ### getToken
300
+
301
+ Returns the information of a given ERC20 token.
302
+
303
+ ```js
304
+ const token: TokenInfoResponse = await safeService.getToken(tokenAddress)
305
+ ```
306
+
307
+ ## <a name="license">License</a>
308
+
309
+ This library is released under MIT.
310
+
311
+ ## <a name="contributors">Contributors</a>
312
+
313
+ - Germán Martínez ([germartinez](https://github.com/germartinez))