Get up and running with zkHole in under 5 minutes. This guide will walk you through the basic setup and your first anonymous transaction.
Install the zkHole SDK and Solana Web3.js library using npm or yarn:
npm install @zkhole/sdk @solana/web3.jsyarn add @zkhole/sdk @solana/web3.jspnpm add @zkhole/sdk @solana/web3.jsConnect to a Solana wallet. This example uses Phantom, but works with any wallet adapter:
// Check if wallet is available
if (!window.solana) {
throw new Error('Please install a Solana wallet');
}
// Connect to the wallet
const wallet = await window.solana.connect();
console.log('Connected to wallet:', wallet.publicKey.toString());
// Listen for account changes
window.solana.on('accountChanged', (publicKey) => {
if (publicKey) {
console.log('Switched to account:', publicKey.toString());
} else {
console.log('Wallet disconnected');
}
});Create a zkHole client instance with your wallet and network configuration:
import { ZkHoleClient } from '@zkhole/sdk';
import { Connection, clusterApiUrl } from '@solana/web3.js';
// Create Solana connection
const connection = new Connection(
clusterApiUrl('mainnet-beta'),
'confirmed'
);
// Initialize zkHole client
const client = new ZkHoleClient({
connection,
wallet: window.solana,
network: 'mainnet-beta', // or 'devnet' for testing
});
console.log('zkHole client initialized');💡 Tip: Use 'devnet' during development to avoid spending real SOL while testing.
Send your first anonymous transaction using zkHole:
// Prepare transaction parameters
const txParams = {
recipient: 'RECIPIENT_WALLET_ADDRESS_HERE',
amount: 1.5, // Amount in SOL
memo: 'Optional transaction memo'
};
try {
// Send anonymous transaction
const transaction = await client.sendAnonymous(txParams);
console.log('Transaction successful!');
console.log('Signature:', transaction.signature);
console.log('Status:', transaction.status);
console.log('Timestamp:', transaction.timestamp);
// Wait for confirmation
const confirmation = await client.confirmTransaction(
transaction.signature
);
console.log('Transaction confirmed:', confirmation);
} catch (error) {
console.error('Transaction failed:', error.message);
}Here's a full working example putting it all together:
import { ZkHoleClient } from '@zkhole/sdk';
import { Connection, clusterApiUrl } from '@solana/web3.js';
async function sendAnonymousTransaction() {
try {
// 1. Connect wallet
if (!window.solana) {
throw new Error('Please install a Solana wallet');
}
const wallet = await window.solana.connect();
console.log('Wallet connected:', wallet.publicKey.toString());
// 2. Create connection
const connection = new Connection(
clusterApiUrl('mainnet-beta'),
'confirmed'
);
// 3. Initialize client
const client = new ZkHoleClient({
connection,
wallet: window.solana,
network: 'mainnet-beta',
});
// 4. Send transaction
const transaction = await client.sendAnonymous({
recipient: 'RECIPIENT_ADDRESS_HERE',
amount: 1.0,
memo: 'Anonymous transfer via zkHole'
});
console.log('Success! Signature:', transaction.signature);
return transaction;
} catch (error) {
console.error('Error:', error);
throw error;
}
}
// Usage
sendAnonymousTransaction()
.then(() => console.log('Done!'))
.catch((err) => console.error('Failed:', err));