Skip to content

Commit

Permalink
Merge pull request #13 from AmbireTech/batch-transactions-md-update
Browse files Browse the repository at this point in the history
Batch transactions md update
  • Loading branch information
ivopaunov authored Feb 5, 2024
2 parents 844ebba + 580c64d commit 5342e64
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions how-to-create-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,52 @@ const safeTxHash1: string = sdk.txs.send({ txs: tnx1 });
const safeTxHash2: string = await sdk.txs.send({ txs: tnx2 });
```

##### Batching transactions if sequence does NOT matter (will work with Wallet Connect as well)

```
...
// NOTE: for wallet connect or the connector used:
// e.g. const txs1 = contract.approve(address, amount)
const actions = [txs1, txs2]
const res = await Promise.all(actions)
```

##### Batching transactions is sequence MATTERS (will work with gnosis and Wallet Connect)

```
...
async function timeout(ms = 420) {
return new Promise(resolve => setTimeout(resolve, ms))
}
// NOTE: for wallet connect or the connector used:
// This way the action is not initiated immediately
// e.g. const txs1 = async () => sdk.txs.send({ txs: tnx1 })
// e.g. const txs1 = async () => contract.approve(address, amount)
const actions = []
// NOTE the `txs1()` here
actions.push(txs1())
// NOTE: timeout in the range 420-690 should work
// This is required due to network latency (WC case especially) and the way Ambire Wallet
// handle the transaction - executed in the sequence they are received
await timeout(690)
actions.push(txs2())
// and so on if there are more actions
const res = await Promise.all(actions)
```

#### Example of gas estimation
```
import { useSafeAppsSDK, BaseTransaction } from '@gnosis.pm/safe-apps-react-sdk'
Expand Down

0 comments on commit 5342e64

Please sign in to comment.