A Go-based CLI application for peer-to-peer cryptocurrency transactions over local networks without internet connectivity. Uses TCP for data transfer, UDP for peer discovery, and Ed25519 for cryptographic signatures.
- Offline P2P transactions over Wi-Fi Direct, hotspot, or localhost
- Ed25519 cryptographic signatures with fingerprint-based identity
- UDP broadcast peer discovery with TCP block transfer
- Simple blockchain (one transaction = one block)
- JSON persistence for keys, state, and ledger
- Deterministic port assignment for multi-wallet support
- Real-time transaction validation and balance updates
- Go 1.21 or higher
- Linux/macOS/Windows
- Network connectivity between peers (local network, no internet required)
# Clone the repository
git clone git@github.com:yourusername/barter.git
cd barter
# Build the binary
go build -o barter .
# Or use make
make build./barter --wallet <name>On first run, the wallet generates an Ed25519 keypair and initializes with 100 tokens.
- Send Money - Discover peers and send tokens
- View Blockchain - Display transaction history
- View Peers - Scan for active wallets on network
- Exit - Shutdown wallet
Open two terminals and run:
# Terminal 1
./barter --wallet alice
# Terminal 2
./barter --wallet bobAlice and Bob can now discover each other and exchange tokens.
Each wallet consists of:
- Ed25519 key pair with 4-character fingerprint
- Persistent JSON storage (keys, state, ledger)
- TCP listener for incoming transactions
- UDP listener for peer discovery
- Deterministic port assignment based on wallet name
Peer Discovery (UDP broadcast)
- Wallets broadcast discovery requests
- Peers respond with their identity and TCP port
- Each wallet uses a unique UDP port (TCP port + 1000)
Transaction Transfer (TCP)
- Sender creates signed block
- Block sent to receiver's TCP port
- Receiver validates signature and updates balance
- Both wallets persist the transaction
Each block contains:
- Index, sender/receiver public keys, amount
- Timestamp, nonce, previous hash
- Transaction ID (SHA-256 of block data)
- Ed25519 signature
Validation includes:
- Signature verification
- Timestamp tolerance check
- Previous hash chain verification
- Double-spend prevention
wallets/
<wallet-name>/
keys.json # Ed25519 keypair and fingerprint
state.json # Balance and last sender hashes
ledger.json # Full blockchain
make buildmake clean.
├── main.go # Core wallet implementation
├── go.mod # Go module definition
├── Makefile # Build automation
└── README.md # Documentation
- Ed25519 signatures prevent transaction forgery
- Timestamp validation prevents replay attacks
- Previous hash linking prevents chain manipulation
- Private keys stored locally (never transmitted)
This is a demonstration project. For production use, additional security measures would be required including:
- Secure key storage (hardware security modules)
- Network encryption (TLS)
- Consensus mechanism for distributed ledger
- Rate limiting and DoS protection
MIT License - see LICENSE file for details.
Built as a demonstration of P2P networking, cryptography, and blockchain concepts in Go.