A comprehensive Next.js demonstration application showcasing Terra Money wallet integration, blockchain transactions, and DeFi functionality. This project serves as a practical guide for developers building Terra-based decentralized applications (dApps).
- Multi-Wallet Support: Connect with Terra Station, Leap Wallet, and other compatible wallets
- Network Management: Switch between mainnet and testnet environments
- Wallet Status Monitoring: Real-time connection status and wallet information
- Transaction Processing: Send tokens with customizable fees and gas settings
- Query Operations: Query account balances, token information, and blockchain data
- Message Signing: Sign arbitrary messages and transaction data
- IBC Transfers: Cross-chain token transfers using Inter-Blockchain Communication
- CW20 Token Support: Manage and interact with Terra's smart contract tokens
- Token Management: Add, remove, and track CW20 tokens in your wallet
- Cross-Chain Assets: Handle IBC-wrapped assets like USDC from Axelar
- Frontend Framework: Next.js 12 with React 17
- Blockchain SDK: Terra.js 3.1.6 for Terra blockchain interaction
- Wallet Integration: Terra Money Wallet Provider 3.6.5
- Styling: Styled Components for component-based styling
- Language: TypeScript for type-safe development
- Package Manager: Yarn for dependency management
- Node.js 14.x or higher
- Yarn package manager
- Terra Station wallet browser extension
-
Clone the repository
git clone https://github.com/your-username/terra-money-wallet-provider-nextjs-demo.git cd terra-money-wallet-provider-nextjs-demo -
Install dependencies
yarn install
-
Start development server
yarn dev
-
Open your browser Navigate to
http://localhost:4300to view the application
import { useWallet, WalletStatus } from '@terra-money/wallet-provider';
const ConnectSample = () => {
const { status, connect, disconnect } = useWallet();
return (
<div>
{status === WalletStatus.WALLET_NOT_CONNECTED && (
<button onClick={() => connect('EXTENSION')}>
Connect Wallet
</button>
)}
{status === WalletStatus.WALLET_CONNECTED && (
<button onClick={disconnect}>Disconnect</button>
)}
</div>
);
};import { useConnectedWallet, useLCDClient } from '@terra-money/wallet-provider';
const QuerySample = () => {
const lcd = useLCDClient();
const connectedWallet = useConnectedWallet();
useEffect(() => {
if (connectedWallet) {
lcd.bank.balance(connectedWallet.walletAddress)
.then(([coins]) => setBalance(coins.toString()));
}
}, [connectedWallet, lcd]);
return <div>{balance && <pre>{balance}</pre>}</div>;
};import { MsgSend, Fee } from '@terra-money/terra.js';
const TxSample = () => {
const connectedWallet = useConnectedWallet();
const sendTokens = () => {
connectedWallet.post({
fee: new Fee(600000, { uluna: 600000 }),
msgs: [
new MsgSend(
connectedWallet.walletAddress,
'recipient_address',
{ uluna: 1000000 }
)
]
});
};
return <button onClick={sendTokens}>Send Tokens</button>;
};yarn dev- Start development server on port 4300yarn build- Build the application for productionyarn start- Start production serveryarn type-check- Run TypeScript type checking
βββ components/ # React components
β βββ ConnectSample/ # Wallet connection examples
β βββ QuerySample/ # Blockchain query examples
β βββ TxSample/ # Transaction examples
β βββ SignSample/ # Message signing examples
β βββ CW20TokensSample/ # CW20 token management
β βββ NetworkSample/ # Network switching examples
β βββ IBCTransferSample/ # Cross-chain transfer examples
βββ pages/ # Next.js pages
β βββ _app.tsx # App wrapper with wallet provider
β βββ _document.tsx # Document customization
β βββ index.tsx # Main demo page
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
- Mainnet: Columbus-5 (Terra Classic)
- Testnet: Bombay-12
- Custom Networks: Configurable via wallet provider
- Terra Station: Official Terra wallet browser extension
- Leap Wallet: Multi-chain wallet with Terra support
- WalletConnect: Mobile wallet connections
- Other Compatible Wallets: Any wallet implementing Terra wallet standards
The application includes comprehensive error handling for common blockchain scenarios:
- User Denied: User cancels transaction or connection
- Create Tx Failed: Transaction creation errors
- Tx Failed: Transaction execution failures
- Timeout: Network timeout errors
- Unspecified Errors: Generic error handling
- Always verify transaction details before signing
- Use testnet for development and testing
- Implement proper error handling for production
- Validate wallet connections and network states
- Handle private key security according to best practices
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Terra Money Documentation
- Terra.js SDK
- Terra Station Wallet
- Next.js Documentation
- React Documentation
If you encounter any issues or have questions:
- Check the Terra Money Documentation
- Review the Terra.js API Reference
- Open an issue in this repository
- Join the Terra Discord Community
Terra, Terra Money, Terra.js, Wallet Provider, Next.js, React, TypeScript, Blockchain, DeFi, dApp, Smart Contracts, CW20, IBC, Cross-chain, Wallet Integration, Terra Station, Leap Wallet, Cryptocurrency, Web3, Decentralized Applications
Built with β€οΈ for the Terra ecosystem