A tutorial demonstrating cross-chain interaction using PushChain's Universal Ethereum Account (UEA) system. This project showcases how users from different blockchains (Ethereum, Solana, and PushChain) can interact with the same smart contract seamlessly.
👉 Full Tutorial: Read the step-by-step guide on Push.org
The Universal Counter is a full-stack application that demonstrates PushChain's cross-chain capabilities:
- Cross-Chain User Attribution: Automatically identifies users' origin chains (Ethereum, Solana, or PushChain)
- Universal Counter Logic: Maintains separate counters for each blockchain
- Clean Frontend Interface: Simple, elegant counter display
- Real-Time Updates: WebSocket integration for instant counter updates across all users
This tutorial includes a clean implementation of cross-chain counter functionality:
universal-counter/
├── contracts/ # Smart contracts
│ ├── src/
│ │ └── UniversalCounter.sol # Cross-chain counter contract
│ └── README.md
├── app/ # Frontend application
│ ├── src/
│ │ └── App.tsx # Counter UI with cross-chain support
│ └── README.md
└── README.md # This file
Clean, minimal interface showing:
- Total universal count across all chains
- Individual chain counters (ETH, Sol, PC)
- Simple increment functionality
- Cross-chain user attribution
- Universal Ethereum Accounts (UEAs): Leverages PushChain's UEA system to identify users' origin chains
- Chain Attribution: Automatically detects whether a user is from Ethereum, Solana, or PushChain
- Universal Access: Users from any supported chain can interact with the same contract
- Cross-Chain Support: Handles Ethereum, Solana, and Push Chain users
- Chain Attribution: Automatically detects user origin chains
- Event Emission: Real-time updates through blockchain events
- Clean UI: Minimal, professional interface
- Real-Time Updates: WebSocket integration for instant updates
- Responsive Design: Works on desktop and mobile devices
- Cross-Chain Display: Shows counters for all supported chains
- Universal Ethereum Accounts (UEAs): How to identify and work with users from different blockchains
- Cross-Chain Interaction: How to create applications that seamlessly work across multiple blockchains
- Chain Attribution: How to track and attribute user actions to their origin chains
- Event Handling: How to listen for and respond to blockchain events in real-time
- Smart contract development with cross-chain features
- Frontend integration with PushChain UI Kit
- Real-time data visualization
- WebSocket event handling
- Cross-chain user attribution
- Clean UI design principles
- Real-time counter updates
- Chain-specific data display
cd contracts
forge build
forge script script/Deploy.s.sol --rpc-url push_testnet --broadcastcd app
npm install
npm run devUpdate the contract addresses in each app's src/App.tsx file with your deployed contract address.
- Node.js (v16 or higher)
- Foundry for smart contract development
- Basic knowledge of React and TypeScript
- Understanding of blockchain concepts
- PushChain testnet tokens for deployment and testing
Each app needs the deployed contract address:
const CONTRACT_ADDRESS = 'YOUR_DEPLOYED_CONTRACT_ADDRESS'All apps use the PushChain testnet:
const provider = new ethers.JsonRpcProvider(
"https://evm.donut.rpc.push.org/"
);- Connect Wallet: Users connect using Push Universal Account Button
- Chain Detection: Contract reads the caller's origin via
IUEAFactory.getOriginForUEA - Increment Counter: Users click to increment their chain's counter
- Visual Feedback: Per-chain counters (PC / ETH / SOL) and total update
- Live Updates: Counters re-read after each transaction confirms
This tutorial uses hardcoded chain detection (Sepolia + Solana Devnet) for clarity. For dynamic chain discovery, see Universal Counter Dynamic, which also ships a Matter.js physics-based variant in ballsy-app/.
- Contract not found: Verify the contract address in
app/src/App.tsxmatches your deployment - Transaction fails: Check wallet connection and that the connected wallet has testnet tokens
- Counter doesn't update: The frontend re-reads counter values after each tx — refresh if stuck
- "Invalid chain" revert: This contract only accepts Push Chain native, Ethereum Sepolia, and Solana Devnet origins. Other chains will revert.
- PushChain Documentation
- PushChain UI Kit
- Universal Counter Dynamic Tutorial — for dynamic chain discovery + Matter.js variant
- Foundry Documentation
After completing this tutorial, you can:
- Explore advanced cross-chain patterns
- Add more interactive features to the physics simulation
- Implement token rewards for participation
- Create your own cross-chain applications
- Deploy to mainnet networks
Ready to build universal applications! 🌍