Transaction Bundler: Quick Start Guide — Typescript
Learn how to convert two simple transactions into one transaction
Combine two transactions into one transaction
This guide demonstrates how to combine two simple transactions:
- Set allowance on Uniswap
- Swap on Uniswap
Install dependencies
Install the required packages:
Set up your environment
Set your environment variables for your private key, RPC URL, and Compass API key.
Initialize SDK, Wallet, and Account
This step loads your environment variables, sets up the viem wallet client, and initializes your account and the Compass API SDK.
Create wallet client and account
This step creates the wallet client and account using your private key and RPC URL.
Get and sign authorization for transaction batching
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.
Bundle and execute the actions
Bundle the allowance and swap actions, then execute them atomically. This step shows how to combine both actions into a single transaction using the Compass API.
Sign and broadcast the 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.
Full Code
Here is the full script from the tutorial. Copy and paste in your code editor and play around!