Go Wrapper for Wallet Core
This is a Go wrapper for Trust Wallet Core, providing native Go bindings and a Chain Abstraction system for building multi-chain wallet applications.
๐ Features
- Multi-Chain Support: Bitcoin, Ethereum, Cosmos, Cardano, Algorand, and 13+ more chains
- Unified API: Single interface for all blockchain operations
- Chain Abstraction: Abstract away chain-specific complexities
- Wallet Management: Create wallets from mnemonic or private keys
- Transaction Signing: Direct and external signing modes
- Address Validation: Cross-chain address validation
- Production Ready: Used in real-world applications
๐ Prerequisites
- Go 1.23 or later
- CMake
- Ninja build system
- C++ compiler
๐ ๏ธ Setup
-
Build native libraries:
./prepare.sh
-
Install dependencies:
go mod tidy
-
Test the integration:
cd cmd/wallet-cli
go build .
./wallet-cli -command examples
๐๏ธ Project Structure
wrapper/go-wrapper/
โโโ chain_abstraction/ # Chain abstraction system
โ โโโ chains/ # Unified chain implementations
โ โ โโโ chains.go # All chains registration
โ โ โโโ bitcoin_compatible/ # Bitcoin, Litecoin, BCH, Dogecoin
โ โ โโโ ethereum_compatible/ # Ethereum, BSC, Polygon, etc.
โ โ โโโ ... # Other chain implementations
โ โโโ interfaces.go # Core interfaces
โ โโโ factory.go # Chain factory
โโโ cmd/wallet-cli/ # CLI example application
โ โโโ main.go # Main CLI with init() registration
โ โโโ examples.go # Complete integration examples
โโโ core/ # Core wallet functionality
โโโ native/ # Native library files
โโโ go.mod # Go module file
๐ฏ Quick Start
1. Initialize Chain Abstraction
package main
import (
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/chain_abstraction"
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/chain_abstraction/chains"
)
// Global registry instance
var globalRegistry *chain_abstraction.ChainRegistry
// init function to register all chains when package is imported
func init() {
globalRegistry = chain_abstraction.NewChainRegistry()
chains.RegisterAll(globalRegistry)
}
func main() {
// All chains are now registered and ready to use!
availableChains := globalRegistry.ListChains()
fmt.Printf("Registered %d chains\n", len(availableChains))
}
2. Create Multi-Chain Wallets
func createWallets(mnemonic string) {
for _, chain := range globalRegistry.ListChains() {
wallet, err := chain.CreateWallet(mnemonic)
if err != nil {
log.Printf("Failed to create %s wallet: %v", chain.GetName(), err)
continue
}
fmt.Printf("โ
%s: %s\n", chain.GetName(), wallet.Address)
}
}
3. Validate Addresses
func validateAddress(address string) {
for _, chain := range globalRegistry.ListChains() {
if chain.ValidateAddress(address) {
fmt.Printf("โ
%s: Valid\n", chain.GetName())
} else {
fmt.Printf("โ %s: Invalid\n", chain.GetName())
}
}
}
๐ Supported Chains
Bitcoin Compatible (4 chains)
- Bitcoin (BTC) - Coin Type: 0
- Litecoin (LTC) - Coin Type: 2
- Bitcoin Cash (BCH) - Coin Type: 145
- Dogecoin (DOGE) - Coin Type: 3
Ethereum Compatible (5 chains)
- Ethereum (ETH) - Coin Type: 60
- Binance Smart Chain (BSC) - Coin Type: 20000714
- Polygon (MATIC) - Coin Type: 966
- Avalanche C-Chain (AVAX) - Coin Type: 10009000
- Arbitrum (ARB) - Coin Type: 10042221
Other Chains (9 chains)
- Cosmos (ATOM) - Coin Type: 118
- Cardano (ADA) - Coin Type: 1815
- Algorand (ALGO) - Coin Type: 283
- Hedera (HBAR) - Coin Type: 3030
- NEAR (NEAR) - Coin Type: 397
- XRP (XRP) - Coin Type: 144
- EOS (EOS) - Coin Type: 194
- VeChain (VET) - Coin Type: 818
- Internet Computer (ICP) - Coin Type: 223
๐ฎ CLI Examples
The cmd/wallet-cli
provides a complete example application:
# List all available chains
./wallet-cli -command list-chains
# Create wallet from mnemonic
./wallet-cli -command create-wallet -chain Bitcoin -mnemonic "your mnemonic here"
# Create wallet from private key
./wallet-cli -command create-wallet -chain Ethereum -private-key "your_private_key_hex"
# Create transaction
./wallet-cli -command create-tx -chain Bitcoin -to "recipient_address" -amount "1000" -private-key "your_private_key_hex"
# Run complete integration demo
./wallet-cli -command examples
๐ง Development
Adding a New Chain
- Create chain implementation in
chain_abstraction/chains/
- Register in
chains.go
:
var AllChains = map[core.CoinType]chain_abstraction.Chain{
// ... existing chains
core.CoinTypeNewChain: newchain.NewNewChain(),
}
- Test with CLI:
./wallet-cli -command examples
Building
# Build the CLI
cd cmd/wallet-cli
go build .
# Run tests
go test ./...
๐ Documentation
๐ Security
- Private keys are never stored in plain text
- Supports hardware wallet integration via external signing
- Built on Trust Wallet Core's security foundation
- Comprehensive input validation and error handling
๐ค Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all examples pass
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.