RAILGUN Reloaded
    Preparing search index...

    Transfer and Unshield

    A transfer pays private notes to 0zk addresses. An unshield pays public tokens to a 0x address. Both spend Spendable notes and make a Groth16 proof.

    The SDK does not include a proving library. Pass a prover to RailgunClient.create(). For Mopro:

    import mopro from '@railgun-reloaded/mopro-wasm'
    import { createGroth16ForEngine } from '@railgun-reloaded/prover'

    await mopro.initialize()
    const client = await RailgunClient.create({ prover: createGroth16ForEngine(mopro) })

    Without a prover, buildTransfer and buildUnshield throw ProverNotConfiguredError.

    Each call takes loadArtifact(variant). It returns the circuit artifact for the variant that the note selection needs. Load it from disk, or with @railgun-reloaded/ipfs-artifact-fetcher.

    The proof needs the local commitment tree. Run sync() in the same client before you transfer or unshield.

    import { createPublicClient, http } from 'viem'
    import { base } from 'viem/chains'

    const publicClient = createPublicClient({ chain: base, transport: http() })

    const result = await client.transfer({
    walletId,
    encryptionKey,
    recipients: [
    { tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', amount: 500_000n, recipient: '0zk1...' }
    ],
    memoText: 'invoice 12',
    showSenderAddressToRecipient: false,
    loadArtifact,
    publicClient,
    signer
    }, 8453)

    The publicClient reads rootHistory on the RAILGUN contract before the proof. Its chain must be the chain of the call.

    const result = await client.unshield({
    walletId,
    encryptionKey,
    tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
    amount: 1_000_000n,
    recipient: '0xYourPublicAddress',
    loadArtifact,
    publicClient,
    signer
    }, 8453)

    The recipient is a 0x address. A 0zk address throws InvalidUnshieldRecipientError.

    On a PPOI network, submit a proof for each railgunTxid after the transaction confirms. Run sync() first.

    await client.sync(walletId, encryptionKey, { chainId })
    for (const railgunTxid of result.railgunTxids) {
    await client.submitPoi({ walletId, encryptionKey, railgunTxid, listKeys, prover: poiProver }, chainId)
    }

    A failed submit does not undo the transaction. Call submitPoi again.

    buildTransfer and buildUnshield take a transport. Use { type: 'self-signed' } to send from your own account. Use { type: 'broadcaster', feeNote, minGasPrice } to pay a broadcaster from the private balance. See "@railgun-reloaded/wallet-sdk/node".Transport and createBroadcasterFeeNote().

    Error Cause
    NoSpendableNotesError No Spendable note of the token exists.
    SolverError (from @railgun-reloaded/utxo-manager) The notes sum to less than the amount plus the fee.
    UnknownMerkleRootError The contract never had the local merkle root. Rescan, or check the RPC.
    InvalidTransferRecipientError A recipient entry is malformed. The error names its index.
    TransferEventMissingError, UnshieldEventMissingError The confirmed receipt has no RAILGUN event.