Monero Wallet RPC Integration: A Complete Guide
How we integrated Monero wallet RPC with Tari asset tokenization
๐ Overview
We built a complete Monero wallet RPC integration for the MyZubster Gateway โ a system that tokenizes real-world assets on the Tari blockchain (Monero's Layer 2).
This guide covers:
Wallet RPC setup and configuration
Transaction monitoring
Balance management
Integration with the gateway
๐๏ธ Architecture
text
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MONERO โ
โ (Privacy Layer) โ
โ โ โ
โ โผ โ
โ WALLET RPC โ
โ (Port 18081) โ
โ โ โ
โ โโโโโโโโโโดโโโโโโโโโ โ
โ โผ โผ โ
โ GATEWAY API DASHBOARD โ
โ (Port 3001) (Port 8080) โ
โ โ โ โ
โ โโโโโโโโโโฌโโโโโโโโโ โ
โ โผ โ
โ TOKENIZED ASSETS โ
โ (MRE, SRE, etc.) โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ๏ธ Setup & Configuration
- Install Monero bash
apt update
apt install monero -y
- Create a Wallet bash
Create a new wallet
echo -e "password\npassword" | \
monero-wallet-cli \
--generate-new-wallet /root/monero-wallet/gateway-wallet \
--daemon-address node.moneroworld.com:18089
- Start Wallet RPC bash
monero-wallet-rpc \
--wallet-file /root/monero-wallet/gateway-wallet \
--password "YOUR_PASSWORD" \
--rpc-bind-port 18081 \
--disable-rpc-login \
--daemon-address node.moneroworld.com:18089 \
--trusted-daemon &
๐ก API Reference
Get Balance
bash
curl -X POST http://localhost:18081/json_rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "get_balance"
}' | jq '.'
Get Address
bash
curl -X POST http://localhost:18081/json_rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "get_address"
}' | jq '.'
Send Transaction
bash
curl -X POST http://localhost:18081/json_rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "transfer",
"params": {
"destinations": [
{
"address": "RECIPIENT_ADDRESS",
"amount": 1000000000000
}
],
"mixin": 16,
"priority": 1,
"get_tx_key": true
}
}' | jq '.'
List Incoming Transfers
bash
curl -X POST http://localhost:18081/json_rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "get_transfers",
"params": {
"in": true
}
}' | jq '.'
Check Transaction Confirmations
bash
curl -X POST http://localhost:18081/json_rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "get_transfers",
"params": {
"in": true,
"out": true
}
}' | jq '.result.in[0].confirmations'
๐ Security Best Practices
-
Password Management
Store passwords in environment variables
Use strong passwords (mix of letters, numbers, symbols)
Never hardcode passwords in scripts
RPC Security
bash
Enable authentication
monero-wallet-rpc \
--rpc-bind-port 18081 \
--rpc-login username:password \
--wallet-file /path/to/wallet
- Firewall Configuration bash
Allow only localhost
ufw allow from 127.0.0.1 to any port 18081
- Wallet Backup bash
Backup wallet files
tar -czf wallet-backup.tar.gz /root/monero-wallet/
๐ณ Docker Deployment
Docker Compose Example
yaml
version: '3.8'
services:
monero-wallet:
image: monero:latest
container_name: monero-wallet
command: >
monero-wallet-rpc
--wallet-file /wallet/gateway-wallet
--password YOUR_PASSWORD
--rpc-bind-port 18081
--disable-rpc-login
--daemon-address node.moneroworld.com:18089
--trusted-daemon
ports:
- "18081:18081"
volumes:
- ./monero-wallet:/wallet
restart: unless-stopped
๐ Troubleshooting
Common Issues
- "No connection to daemon"
Solution: Use a different public node or start your own daemon
bash
Alternative nodes
--daemon-address xmr-node.cakewallet.com:18081
--daemon-address monero.fail:18081
- "Invalid password"
Solution: Check password and try again
bash
Reset wallet
rm -f /root/monero-wallet/*.lock
- "Not enough money"
Solution: Wait for confirmations (10 blocks = ~20 minutes)
bash
Check unlock status
curl -X POST http://localhost:18081/json_rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"get_balance"}' \
| jq '.result.unlocked_balance'
- "Resource temporarily unavailable"
Solution: Remove lock file
bash
rm -f /root/monero-wallet/*.lock
๐ Monitoring
Health Check Script
bash
!/bin/bash
check-wallet.sh
RPC_URL="http://localhost:18081/json_rpc"
response=$(curl -s -X POST $RPC_URL \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"get_balance"}')
if echo "$response" | jq -e '.result' > /dev/null; then
echo "โ
Wallet RPC is running"
balance=$(echo "$response" | jq '.result.balance')
unlocked=$(echo "$response" | jq '.result.unlocked_balance')
echo "Balance: $balance"
echo "Unlocked: $unlocked"
else
echo "โ Wallet RPC is not responding"
exit 1
fi
Cron Job for Monitoring
bash
Check every 5 minutes
*/5 * * * * /root/check-wallet.sh >> /var/log/wallet-monitor.log
๐ฏ Integration with Gateway
.env Configuration
env
Monero Wallet RPC
MONERO_RPC_URL=http://localhost:18081
MONERO_WALLET_ADDRESS=4APG2UXM1XS6aE8XTw397TSPuExwXoh5vd8GgjFDxmaXeWePDbcXdM2CujviKPprW2NczN2WdKKGqLUn1FJ3PSGRSkLnMTG
MONERO_WALLET_PASSWORD=YOUR_PASSWORD
MONERO_RPC_USERNAME=
MONERO_RPC_PASSWORD=
MONERO_NETWORK=mainnet
MONERO_MIN_CONFIRMATIONS=10
Node.js Integration
javascript
// wallet.js
const axios = require('axios');
class MoneroWallet {
constructor(rpcUrl, password) {
this.rpcUrl = rpcUrl;
this.password = password;
}
async getBalance() {
const response = await axios.post(this.rpcUrl, {
jsonrpc: '2.0',
id: '1',
method: 'get_balance'
}, {
headers: { 'Content-Type': 'application/json' }
});
return response.data.result;
}
async sendTransaction(address, amount) {
const response = await axios.post(this.rpcUrl, {
jsonrpc: '2.0',
id: '1',
method: 'transfer',
params: {
destinations: [{ address, amount }],
mixin: 16,
priority: 1,
get_tx_key: true
}
});
return response.data.result;
}
}
module.exports = MoneroWallet;
๐ Performance Metrics
Operation Average Time
Balance check < 100ms
Send transaction 2-5 seconds
Confirmation 2-10 minutes
Full unlock 20-30 minutes
๐ฎ Future Improvements
โก
Multi-wallet support
โก
WebSocket notifications
โก
Advanced analytics
โก
Integration with Tari smart contracts
โก
Automated backup system
๐ Resources
Monero RPC Documentation
Tari Blockchain
Monero Wallet CLI
๐ค Contributing
We welcome contributions! Check our Spiccioli bounty system for paid tasks.
Built with โค๏ธ on Tari ยท Powered by Monero
Top comments (0)