Skip to content

anton-karlovskiy/terra-money-wallet-provider-nextjs-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Terra Money Wallet Provider Next.js Demo

Next.js Terra.js React TypeScript

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).

πŸš€ Features

Core Wallet Functionality

  • 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

Blockchain Operations

  • 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

DeFi Integration

  • 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

πŸ› οΈ Technology Stack

  • 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

πŸ“¦ Installation

Prerequisites

  • Node.js 14.x or higher
  • Yarn package manager
  • Terra Station wallet browser extension

Setup Instructions

  1. Clone the repository

    git clone https://github.com/your-username/terra-money-wallet-provider-nextjs-demo.git
    cd terra-money-wallet-provider-nextjs-demo
  2. Install dependencies

    yarn install
  3. Start development server

    yarn dev
  4. Open your browser Navigate to http://localhost:4300 to view the application

🎯 Usage Examples

Wallet Connection

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>
  );
};

Query Account Balance

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>;
};

Send Transaction

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>;
};

πŸ”§ Available Scripts

  • yarn dev - Start development server on port 4300
  • yarn build - Build the application for production
  • yarn start - Start production server
  • yarn type-check - Run TypeScript type checking

πŸ“ Project Structure

β”œβ”€β”€ 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

🌐 Supported Networks

  • Mainnet: Columbus-5 (Terra Classic)
  • Testnet: Bombay-12
  • Custom Networks: Configurable via wallet provider

πŸ”— Supported Wallets

  • 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

🚨 Error Handling

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

πŸ”’ Security Considerations

  • 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

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Useful Links

πŸ†˜ Support

If you encounter any issues or have questions:

  1. Check the Terra Money Documentation
  2. Review the Terra.js API Reference
  3. Open an issue in this repository
  4. Join the Terra Discord Community

🏷️ Keywords

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

About

A comprehensive Next.js demo showcasing Terra Money wallet integration, blockchain transactions, and DeFi functionality. Features wallet connection, token transfers, IBC cross-chain operations, and CW20 token management with TypeScript examples.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors