A React application demonstrating how to execute multiple contract calls in a single transaction (multicall) on PushChain using the PushChain UI Kit.
👉 Full Tutorial: Read the step-by-step guide on Push.org
This frontend application provides an interface for executing batch transactions on PushChain. It demonstrates advanced PushChain capabilities by simultaneously interacting with multiple smart contracts in a single transaction, showcasing gas optimization and improved user experience.
- Batch Transactions: Execute multiple contract calls in a single transaction
- Multi-Contract Support: Interact with both Counter and ERC20 contracts simultaneously
- Real-time Updates: Displays both counter value and token balance
- Gas Optimization: Reduced transaction costs through batching
- Universal Wallet Support: Connect from Ethereum, Solana, or any supported chain
- Clean UI: Minimal design with centered layout and clear visual feedback
- Error Handling: Comprehensive error messages and loading states
- TypeScript: Fully typed for better development experience
- Node.js (v16 or higher)
- npm or yarn
- Deployed Counter and ERC20 contracts on PushChain testnet
- Install dependencies:
npm install- Update the contract addresses in
src/App.tsx:
const COUNTER_CONTRACT_ADDRESS = 'YOUR_DEPLOYED_COUNTER_ADDRESS'
const ERC20_CONTRACT_ADDRESS = 'YOUR_DEPLOYED_ERC20_ADDRESS'- Start the development server:
npm run devapp/
├── src/
│ ├── App.tsx # Main application component with batch transactions
│ ├── App.css # Application styles
│ ├── index.css # Global styles
│ ├── abi/
│ │ ├── Counter.json # Counter contract ABI
│ │ └── ERC20.json # ERC20 contract ABI
│ └── providers/
│ └── PushChainProviders.tsx # PushChain provider configuration
├── package.json # Dependencies and scripts
└── README.md # This file
The main application component that includes:
- PushChain Hooks: Uses
usePushWalletContext,usePushChainClient, andusePushChain - State Management: Manages counter value, token balance, loading states, and errors
- Batch Transactions: Executes multiple contract calls in a single transaction
- Multi-Contract Interaction: Reads from and writes to both Counter and ERC20 contracts
- UI Components: Clean, centered layout with wallet connection and real-time updates
The app demonstrates PushChain's batch transaction capabilities:
// Create batch transaction with multiple contract calls
const batchTx = await pushChainClient.universal.sendTransaction({
to: pushChainClient.universal.account,
data: [
{
to: COUNTER_CONTRACT_ADDRESS,
value: BigInt(0),
data: incrementData
},
{
to: ERC20_CONTRACT_ADDRESS,
value: BigInt(0),
data: mintData
},
],
});
// Reading from multiple contracts
const counterContract = new ethers.Contract(COUNTER_CONTRACT_ADDRESS, CounterABI, provider);
const erc20Contract = new ethers.Contract(ERC20_CONTRACT_ADDRESS, ERC20ABI, provider);Configures the PushChain Universal Wallet Provider with:
- Network Configuration: Testnet setup for development
- Wallet Options: Support for multiple wallet types and chains
- App Metadata: Branding and description for wallet connection prompts
- Chain Configuration: Custom RPC endpoints and chain settings
Update both contract addresses after deploying your contracts:
const COUNTER_CONTRACT_ADDRESS = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
const ERC20_CONTRACT_ADDRESS = '0x0165878A594ca255338adfa4d48449f69242Eb8F'The app uses the PushChain testnet RPC endpoint:
const provider = new ethers.JsonRpcProvider(
"https://evm.donut.rpc.push.org/"
);- Page Load: Both counter value and token balance display immediately
- Wallet Connection: Click "Connect Account" to connect wallet
- Batch Transaction: Click "Do Batch Transaction" to execute both operations
- Real-time Updates: Both counter and balance update automatically after the batch transaction
- Token Import: Optional token contract address shown for wallet import
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
The app uses inline styles for simplicity, with a focus on:
- Clean white background
- Centered layout
- Responsive design
- Clear visual hierarchy
Key dependencies include:
- @pushchain/ui-kit: PushChain UI components and hooks for batch transactions
- ethers: Ethereum library for blockchain interactions
- react: Frontend framework
- typescript: Type safety and better development experience
- vite: Build tool and development server
The application executes the following operations in a single transaction:
- Counter Increment: Calls
Counter.increment()to increase counter by 1 - Token Minting: Calls
ERC20.mint()to mint 11 UNICORN tokens to user's address
This demonstrates:
- Gas Efficiency: Multiple operations in one transaction
- Atomic Execution: All operations succeed or fail together
- Better UX: Single confirmation for multiple actions
- Contract not found: Ensure both contract addresses are correct
- Batch transaction fails: Check wallet connection and network
- Values not updating: Verify RPC endpoint and contract deployments
- Token balance not showing: Confirm ERC20 contract is deployed and accessible
The app provides clear error messages for:
- Wallet connection issues
- Batch transaction failures
- Contract interaction problems
- Network connectivity issues
After running this tutorial, you can:
- Implement more complex batch operations (DEX swaps + staking)
- Add batch transaction support to existing dApps
- Explore cross-chain batch transactions
- Build advanced DeFi protocols using multicall patterns
- Optimize gas costs for multi-step workflows