- Free Compass API Key
- Wallet (EOA or smart account guide)
Introduction
This guide demonstrates how to combine two simple transactions:- Set allowance on Uniswap
- Swap on Uniswap
Setup
1
Install Dependencies
Install the required packages.
2
Set Environment Variables
Create a .env file in your project root.
.env
3
Import Libraries & Environment Variables
4
Initialize SDK and Account
The full, uninterrupted code is available at the end of the tutorial.
Get Authorization
Before you can bundle transactions, you need to get an authorization from the Compass API and sign it with your private key. This ensures only you can execute the batch.1
Get and Sign Authorization
Request authorization from the Compass API and sign it with your wallet to authenticate the transaction batching.
Bundle the Actions
Now let’s bundle the allowance and swap actions for atomic execution. This step shows how to combine both actions into a single transaction using the Compass API.1
Create Bundled Transaction
Bundle the allowance and swap actions for atomic execution. This step shows how to combine both actions into a single transaction using the Compass API.Any transactional endpoint in Compass API can be turned into an action, see API Reference.
Execute the Transaction
The final step is to sign and broadcast the transaction to the network. This will execute your bundled actions in a single atomic transaction.1
Sign and Broadcast Transaction
Sign the returned transaction with your private key and broadcast it to the network. This is the final step to actually send your bundled transaction to Ethereum.
For further practice, try bundling different combinations of actions, test with various token pairs, or explore other Compass Bundler features to create more complex transaction bundles.