Confidential Transfers

Transfers tokens to destination without disclosing the amount

WEB3.JS

import { Connection, Keypair, clusterApiUrl } from '@solana/web3.js';
import { createMint, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';
import walletSecret from './wallet.json'

const wallet = Keypair.fromSecretKey(new Uint8Array(walletSecret));
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');

async function createConfidentialToken() {
    try {
        const mintKeypair = Keypair.generate();

        const mint = await createMint(
            connection,
            wallet,
            wallet.publicKey,
            null, // Freeze authority (optional)
            0, // Decimals
            mintKeypair,
            { commitment: 'confirmed' },
            TOKEN_2022_PROGRAM_ID 
        );
        console.log('Mint created:', mint.toBase58());
        return mint;
    } catch (error) {
        console.error('Error creating token:', error);
        throw error;
    }
}

const main = async () => {
    try {
        const mint = await createConfidentialMint();
        console.log('Token created:', mint.toBase58());
    } catch (error) {
        console.error('Error in main:', error);
    }
}

main();

CLI

There is 9 extra steps involved when dealing with Confidential Transfers using Solana Token Extensions

  1. Create token
spl-token --program-2022 create-token --enable-confidential-transfers auto --decimals 0
  1. Create sender account
spl-token create-account <mint_pubkey>

Note:- The destination account will need to create their own account to be able receive

  1. Enable Confidential Transfers for the account
spl-token configure-confidential-transfer-account <mint_pubkey>
  1. Mint tokens
spl-token mint <mint_pubkey> 1
  1. Deposit
spl-token deposit-confidential-tokens <mint_pubkey> 1
  1. Apply on sender account
spl-token apply-pending-balance <mint_pubkey>
  1. Transfer to destination
spl-token transfer <mint_pubkey> 1 <dest_pubkey> --confidential 
  1. Apply to destination account
spl-token apply-pending-balance --address <destination_pubkey>
  1. Withdraw at destination
spl-token withdraw-confidential-tokens <mint_pubkey> 1 --address <dest_pubkey>