@gnosis.pm/safe-apps-sdk
Advanced tools
Comparing version 0.4.2 to 1.0.0-beta.0
{ | ||
"name": "@gnosis.pm/safe-apps-sdk", | ||
"version": "0.4.2", | ||
"version": "1.0.0-beta.0", | ||
"description": "SDK developed to integrate third-party apps with Safe-Multisig app.", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"main": "dist/src/index.js", | ||
"typings": "dist/src/index.d.ts", | ||
"files": [ | ||
@@ -17,3 +17,3 @@ "dist/**/*", | ||
"scripts": { | ||
"test": "jest", | ||
"test": "jest --verbose", | ||
"build": "yarn rimraf dist && yarn tsc", | ||
@@ -26,20 +26,28 @@ "prepare": "yarn build", | ||
"license": "MIT", | ||
"dependencies": { | ||
"semver": "^7.3.2", | ||
"web3-core": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.14", | ||
"@types/node": "^14.11.2", | ||
"@typescript-eslint/eslint-plugin": "^4.2.0", | ||
"@typescript-eslint/parser": "^4.2.0", | ||
"eslint": "^7.9.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^14.14.8", | ||
"@types/semver": "^7.3.4", | ||
"@typescript-eslint/eslint-plugin": "^4.8.1", | ||
"@typescript-eslint/parser": "^4.8.1", | ||
"eslint": "^7.13.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"husky": "^4.3.0", | ||
"jest": "^26.4.2", | ||
"lint-staged": "^10.4.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.1", | ||
"prettier": "^2.1.2", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^26.4.0", | ||
"ts-jest": "^26.4.4", | ||
"tslint": "^6.1.3", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^4.0.3" | ||
"typescript": "^4.0.5" | ||
}, | ||
"peerDependencies": { | ||
"web3-core": "^1.3.0" | ||
}, | ||
"husky": { | ||
@@ -46,0 +54,0 @@ "hooks": { |
225
README.md
@@ -31,59 +31,34 @@ # Safe Apps SDK | ||
Apps built with this Sdk are meant to be run in an iframe inside the Safe Web UI. | ||
This library exposes a single method called `initSdk` that receives a single optional parameter, an array of regular expressions. By default it's configured to accept messages from this URLs: | ||
Apps built with the Safe Apps SDK are meant to be run in an iframe inside the Safe Web UI. | ||
This library exposes a class as a default export. It accepts an optional options object: | ||
`whitelistedDomains` - Array of regular expressions for origins you want to accept messages from. If not passed, accepts | ||
messages from any origin (default). | ||
- mainnet: https://gnosis-safe.io, | ||
- mainnet-staging: https://safe-team.staging.gnosisdev.com, | ||
- rinkeby: https://rinkeby.gnosis-safe.io, | ||
- rinkeby-staging: https://safe-team-rinkeby.staging.gnosisdev.com, | ||
- rinkeby-dev: https://safe-team.dev.gnosisdev.com | ||
- localhost (for the desktop app) | ||
```js | ||
import SafeAppsSDK from '@gnosis.pm/safe-apps-sdk'; | ||
By passing the argument to `initSdk` you can add more URLs to the list. It's useful when you are running your own instance of Safe Multisig. | ||
const opts = { | ||
whitelistedDomains: [/gnosis-safe\\.io/], | ||
}; | ||
```js | ||
import initSdk from '@gnosis.pm/safe-apps-sdk'; | ||
const appsSdk = initSdk(); | ||
const appsSdk = new SafeAppsSDK(opts); | ||
``` | ||
It returns a SDK instance that allows you to interact with the Safe Multisig application. | ||
The instance allows you to interact with the Safe Multisig application. | ||
### Subscribing to events | ||
### Getting Safe information | ||
Once you get the SDK instance, you will be able to subscribe to events from the Safe Multisig. | ||
Safe information can be obtained by calling `.getSafeInfo()` | ||
The SDK instance exposes a method called `addListeners` that receives an object with known keys, over these keys you will be able to subscribe to different events. | ||
- `onSafeInfo`: It will provide you first level information like the safeAddress, network, etc. | ||
- `onTransactionConfirmation`: Fired when the user confirms the transaction inside his wallet. The response will include the `requestId` and `safeTxHash` of the transaction. | ||
- `onTransactionRejection`: Fired when the user rejects the transaction inside his wallet. The response will include the `requestId`. | ||
```js | ||
import { SafeInfo } from '@gnosis.pm/safe-apps-sdk'; | ||
const onSafeInfo = (safeInfo: SafeInfo): void => { | ||
console.log(safeInfo); | ||
}; | ||
const onTransactionConfirmation = ({ requestId, safeTxHash }) => { | ||
console.log(requestId, safeTxHash); | ||
}; | ||
const onTransactionRejection = ({ requestId }) => { | ||
console.log(requestId); | ||
}; | ||
appsSdk.addListeners({ | ||
onSafeInfo, | ||
onTransactionConfirmation, | ||
onTransactionRejection, | ||
}); | ||
const safe = await appsSdk.getSafeInfo(); | ||
// { | ||
// "safeAddress": "0x2fC97b3c7324EFc0BeC094bf75d5dCdFEb082C53", | ||
// "network": "RINKEBY" | ||
// } | ||
``` | ||
You can remove listeners by calling `appsSdk.removeListeners()`. | ||
### Sending TXs | ||
Sending a TX through the Safe Multisig is as simple as invoking `sendTransaction` method with an array of TXs. | ||
Sending a TX through the Safe Multisig is as simple as invoking `.txs.send()` | ||
@@ -108,9 +83,14 @@ ```js | ||
// Send to Safe-multisig | ||
const message = appsSdk.sendTransactions(txs); | ||
console.log(message.requestId); | ||
const params = { | ||
safeTxGas: 500000, | ||
}; | ||
try { | ||
const txs = await appsSdk.txs.send({ txs, params }); | ||
// { safeTxHash: '0x...' } | ||
} catch (err) { | ||
console.error(err.message); | ||
} | ||
``` | ||
`sendTransactions` returns a message containing the requestId. You can use it to map transaction calls with `onTransactionConfirmation` events. | ||
> Note: `value` accepts a number or a string as a decimal or hex number. | ||
@@ -120,10 +100,146 @@ | ||
Once you received safe transaction hash from `onTransactionConfirmation` event listener, you might want to get the status of the transaction (was it executed? how many confirmations does it have?): | ||
Once you received safe transaction hash, you might want to get the status of the transaction (was it executed? how many confirmations does it have?): | ||
```js | ||
const tx = sdk.txs.getBySafeTxHash(safeTxHash); | ||
const tx = await sdk.txs.getBySafeTxHash(safeTxHash); | ||
``` | ||
It will return the following structure https://github.com/gnosis/safe-apps-sdk/blob/development/src/types.ts#L157 or throw an error if the backend hasn't synced the transaction yet | ||
It will return the following structure https://github.com/gnosis/safe-apps-sdk/blob/development/src/types.ts#L182 or throw an error if the backend hasn't synced the transaction yet | ||
## RPC Calls | ||
### The default block parameter | ||
The following methods have an extra default block parameter: | ||
- getBalance | ||
- getCode | ||
- getStorageAt | ||
- call | ||
When requests are made that act on the state of ethereum, the last default block parameter determines the height of the block. | ||
The following options are possible for the defaultBlock parameter: | ||
`HEX String` - an integer block number | ||
`String "earliest"` for the earliest/genesis block | ||
`String "latest"` - for the latest mined block (default) | ||
`String "pending"` - for the pending state/transactions | ||
### getBalance | ||
Returns the balance of the account of given address. | ||
```js | ||
const balance = await appsSdk.eth.getBalance(['0x...']); | ||
``` | ||
### getCode | ||
Returns code at a given address. | ||
```js | ||
const code = await appsSdk.eth.getCode(['0x...']); | ||
``` | ||
### getStorageAt | ||
Returns the value from a storage position at a given address. | ||
```js | ||
const value = await appsSdk.eth.getStorageAt(['0x...', 0]); | ||
``` | ||
### call | ||
Executes a new message call immediately without creating a transaction on the block chain. | ||
```js | ||
const config = { | ||
from: '0x0000000000000000000000000000000000000000', | ||
to: '0x0000000000000000000000000000000000000000', | ||
}; | ||
const result = await appsSdk.eth.call([config]); | ||
``` | ||
The transaction call object: | ||
`from` - (optional) The address the transaction is sent from. | ||
`to` 20 Bytes - The address the transaction is directed to. | ||
`gas` - (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions. | ||
`gasPrice` - (optional) Integer of the gasPrice used for each paid gas | ||
`value` - (optional) Integer of the value sent with this transaction | ||
`data` - (optional) Hash of the method signature and encoded parameters. For details see [Ethereum Contract ABI in the Solidity documentation](https://docs.soliditylang.org/en/latest/abi-spec.html) | ||
### getPastLogs | ||
Returns an array of all logs matching a given filter object. | ||
```js | ||
const params = [ | ||
{ | ||
fromBlock: 11054275, | ||
toBlock: 'latest', | ||
}, | ||
]; | ||
const logs = await appsSdk.eth.getPastLogs([params]); | ||
``` | ||
The filter options: | ||
`fromBlock` - Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. | ||
`toBlock` - Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. | ||
`address` - (optional) Contract address or a list of addresses from which logs should originate. | ||
`topics` - (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with “or” options. | ||
### getBlockByHash | ||
Returns information about a block by hash. | ||
```js | ||
const hash = '0x1955a9f306903669e295196752b11bc0dee33b48cabdf44b1103b7cea086cae7'; | ||
const block = await appsSdk.eth.getBlockByHash([hash, true]); | ||
``` | ||
Parameters | ||
`DATA` - Hash of a block. | ||
`Boolean` (default: false) - If true it returns the full transaction objects, if false only the hashes of the transactions. | ||
### getBlockByNumber | ||
Returns information about a block by block number. | ||
```js | ||
const number = 11054275; | ||
const block = await appsSdk.eth.getBlockByNumber([number]); | ||
``` | ||
Parameters | ||
`QUANTITY|TAG` - integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter. | ||
`Boolean` (default: false) - If true it returns the full transaction objects, if false only the hashes of the transactions. | ||
### getTransactionByHash | ||
Returns the information about a transaction requested by transaction hash. | ||
```js | ||
const tx = await appsSdk.eth.getTransactionByHash([ | ||
'0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b', | ||
]); | ||
``` | ||
### getTransactionReceipt | ||
Returns the receipt of a transaction by transaction hash. | ||
> Note: That the receipt is not available for pending transactions. | ||
```js | ||
const tx = await appsSdk.eth.getTransactionReceipt([ | ||
'0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238', | ||
]); | ||
``` | ||
## Testing in the Safe Multisig application | ||
@@ -139,4 +255,3 @@ | ||
"description": "A description of what your app do", | ||
"iconPath": "myAppIcon.svg", | ||
"providedBy": { "name": "YourCompanyName", "url": "https://yourcompanyname.io" } | ||
"iconPath": "myAppIcon.svg" | ||
} | ||
@@ -175,3 +290,3 @@ ``` | ||
Additionally you need to create the `config-overrides.js` file in the root of the project to confirgure the **CORS** headers. The content of the file should be: | ||
Additionally, you need to create the `config-overrides.js` file in the root of the project to confirgure the **CORS** headers. The content of the file should be: | ||
@@ -178,0 +293,0 @@ ```js |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
367
16360
3
17
5
0
3
+ Addedsemver@^7.3.2
+ Addedweb3-core@^1.3.0
+ Added@ethereumjs/rlp@4.0.1(transitive)
+ Added@ethereumjs/util@8.1.0(transitive)
+ Added@ethersproject/address@5.7.0(transitive)
+ Added@ethersproject/bignumber@5.7.0(transitive)
+ Added@ethersproject/bytes@5.7.0(transitive)
+ Added@ethersproject/constants@5.7.0(transitive)
+ Added@ethersproject/keccak256@5.7.0(transitive)
+ Added@ethersproject/logger@5.7.0(transitive)
+ Added@ethersproject/properties@5.7.0(transitive)
+ Added@ethersproject/rlp@5.7.0(transitive)
+ Added@ethersproject/signing-key@5.7.0(transitive)
+ Added@ethersproject/transactions@5.7.0(transitive)
+ Added@noble/curves@1.4.2(transitive)
+ Added@noble/hashes@1.4.01.7.1(transitive)
+ Added@scure/base@1.1.9(transitive)
+ Added@scure/bip32@1.4.0(transitive)
+ Added@scure/bip39@1.3.0(transitive)
+ Added@types/bn.js@5.1.6(transitive)
+ Added@types/node@12.20.55(transitive)
+ Addedabortcontroller-polyfill@1.7.8(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbignumber.js@9.1.2(transitive)
+ Addedbn.js@4.11.64.12.15.2.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedbufferutil@4.0.9(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcross-fetch@4.1.0(transitive)
+ Addedd@1.0.2(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedelliptic@6.5.4(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedethereum-bloom-filters@1.2.0(transitive)
+ Addedethereum-cryptography@2.2.1(transitive)
+ Addedethjs-unit@0.1.6(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedeventemitter3@4.0.4(transitive)
+ Addedext@1.7.0(transitive)
+ Addedfor-each@0.3.5(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedhttp-https@1.0.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.1.0(transitive)
+ Addedis-hex-prefixed@1.0.0(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-typed-array@1.1.15(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedjs-sha3@0.8.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmicro-ftch@0.3.1(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addedms@2.0.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednode-gyp-build@4.8.4(transitive)
+ Addednumber-to-bn@1.7.0(transitive)
+ Addedoboe@2.1.5(transitive)
+ Addedpossible-typed-array-names@1.1.0(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-regex-test@1.1.0(transitive)
+ Addedsemver@7.7.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedstrip-hex-prefix@1.0.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedtypedarray-to-buffer@3.1.5(transitive)
+ Addedutf-8-validate@5.0.10(transitive)
+ Addedutf8@3.0.0(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedweb3-core@1.10.4(transitive)
+ Addedweb3-core-helpers@1.10.4(transitive)
+ Addedweb3-core-method@1.10.4(transitive)
+ Addedweb3-core-promievent@1.10.4(transitive)
+ Addedweb3-core-requestmanager@1.10.4(transitive)
+ Addedweb3-core-subscriptions@1.10.4(transitive)
+ Addedweb3-eth-iban@1.10.4(transitive)
+ Addedweb3-providers-http@1.10.4(transitive)
+ Addedweb3-providers-ipc@1.10.4(transitive)
+ Addedweb3-providers-ws@1.10.4(transitive)
+ Addedweb3-utils@1.10.4(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwebsocket@1.0.35(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwhich-typed-array@1.1.18(transitive)
+ Addedyaeti@0.0.6(transitive)