LogoLogo
zkBob AppLinks & Resources
  • 🦹zkBob Overview
    • zkBob
    • Basic Concepts
      • Getting Started
      • Open-Source and Decentralized
      • Multichain Deployment
      • Usage Statistics
      • Use Cases
        • Employee Salary
        • Vendor Purchasing
      • Development Timeline
      • zk Privacy Solution Comparison
    • zkBob Pools
      • USDC Pool on Polygon (sunsets January 31, 2025)
      • USDC Pool on Optimism
      • ETH Pool on Optimism
      • USDT Pool on Tron (sunsets Oct 29, 2024)
    • Fees
      • Unspent note handling
    • Deposit & Withdrawal Limits
    • Compliance & Security
      • TRM Labs Integration
    • Conferences, Workshops, Videos
      • International Videos
    • Governance
    • BOB Stablecoin
    • zkBob FAQ
  • πŸ¦Έβ€β™‚οΈzkBob Application
    • UI Overview
    • Account Creation
      • Login to an existing account
      • Lost Password
      • Metamask / Web3 Wallet Warning
    • Deposits
    • Transfers
      • Multitransfers
    • Withdrawals
      • Native Token Conversion
    • Generate a Receiving Address
    • Optional KYC
    • zkBob Direct Deposits
    • Support ID
    • Payment Links
    • Integrated Services
    • Multilingual support
      • PortuguΓͺs
      • Русский
      • δΈ­ζ–‡
  • πŸ‘©β€βš•οΈTechnical Implementation
    • zkBob Application Overview
    • Deployed Contracts
    • Smart Contracts
      • zkBob Pool Contract
        • Transaction Calldata
      • Bob Token Contract
      • Verifier contracts
      • Operator Manager Contract
        • Mutable Operator Manager
      • Voucher (XP) Token Contract
    • Accounts and Notes
      • Accounts
      • Notes
    • Relayer Node
      • Relayer Operations
      • Optimistic State
      • REST API
    • zkBob Keys
      • Address derivation
      • Ephemeral keys
    • zkSNARKs & Circuits
      • Transfer verifier circuit overview
    • zkBob Merkle Tree
      • The Poseidon Hash
    • Elliptic Curve Cryptography
    • Transaction Overview
      • Common Structure
      • Memo Block
        • Memo Block Encryption
      • Transaction Types
      • Nullifiers
      • Signing a Transaction
      • The Transaction Lifecycle
    • Client Library SDK
      • Configuration
        • Initializing the client
          • Client Configuration
        • Attaching a User Account
          • Account Configuration
        • Switching Between Pools
      • Account-less Mode Operations
        • Converting Token Amounts
        • Transaction Fees
        • Transaction Constraints
        • Using the Delegated Prover
        • Getting the State
        • Gift Cards
        • Client Library Status
        • Helpers
        • Versioning
      • Full Mode Operations
        • Balances and History
        • Shielded Addresses
        • Account State
        • Fee Estimations
        • Transaction Configuration
        • Sending Transactions
        • Transaction Maintenance
        • Direct Deposits
        • Gift Cards Maintenance
        • Ephemeral Deposits
        • Forced Exit
        • Other Routines
      • Common Types
      • Full Functions List
      • Utilities
  • πŸ‘©β€πŸ«Deployment
    • Trusted Setup Ceremony
    • Contract Deployment
    • Relayer Subsystem
  • πŸ‘·β€β™‚οΈRoadmap
    • On the Roadmap
    • Exploratory Features
      • XP (Experience Points)
        • XP-based Auctions
      • Multi-chain Custom Rollup Deployment
      • Round-robin Operator Manager
      • Compounding
  • πŸ§‘β€πŸ’»Jobs
    • Zero-Knowledge Researcher & Protocol Developer
  • 🧩Resources
    • Visual Assets
    • Hackathons
      • zkBob Cloud
    • Release Notes
      • October 11, 2023
      • July 13, 2023
      • June 13, 2023
      • March 28, 2023
      • January 30, 2023
      • January 16, 2023
      • January 2, 2023
      • Releases 2022
    • Security Audit
    • Github
    • Link tree
Powered by GitBook
On this page
  • Encoding Gift-Card Parameters
  • Parameters
  • Returns
  • Example
  • Decoding a Gift-Card Code
  • Parameters
  • Returns
  • Example

Was this helpful?

  1. πŸ‘©β€βš•οΈTechnical Implementation
  2. Client Library SDK
  3. Account-less Mode Operations

Gift Cards

Encoding and decoding URLs for gift cards

PreviousGetting the StateNextClient Library Status

Last updated 1 year ago

Was this helpful?

: When distributing a gift-card several parameters are provided to the user including the spending key, birth index, balance, pool address and so on. The easiest way to achieve this is to encode these parameters into the URL. The following methods are intended for creating and parsing a gift card.

Use gift card codes with care. Anyone who knows the code has full access to the gift card funds.

Encoding Gift-Card Parameters

To create gift-card URL code invoke the following method:

async codeForGiftCard(giftCard: GiftCardProperties): Promise<string>

Parameters

giftCard - a object which contains all needed parameters to encode

Returns

Promise returns Base58-encoded string which can be injected into the redeeming URL

Example

const gk: GiftCardProperties = {
    sk: new Uint8Array(
        [ 40, 169, 173, 13, 42, 145, 224, 222, 213, 124, 226, 142, 126, 241, 6, 1,
          42, 133, 48, 12, 96, 66, 213, 158, 112, 225, 75, 198, 172, 82, 148, 3 ]
    ),
    birthIndex: 533888,
    poolAlias: 'BOB-sepolia',
    balance: 10000000000n
};
const code = await zkClient.codeForGiftCard(gk);
const baseURL = 'https://staging--zkbob.netlify.app';
console.log(`Redeem gift-card with: ${baseURL}/?gift-code=${code}`);
// output: Redeem gift-card with: 
// https://staging--zkbob.netlify.app/?gift-code=QvHXyAF2ykRCSTCwiLJbGGJVjJX7M8Xp5vfNNLaiEvwV8BQfYBeR6ivtY7svMpPyCsL6huTHpB

Decoding a Gift-Card Code

Use the following method to retrieve a gift-card from the code or URL containing the code:

async giftCardFromCode(code: string): Promise<GiftCardProperties>
Related Methods

Parameters

code - a gift-card code or URL contained code within the gift-code query parameter.

Returns

Example

const url = 'https://staging--zkbob.netlify.app/?gift-code=QvHXyAF2ykRCSTCwiLJbGGJVjJX7M8Xp5vfNNLaiEvwV8BQfYBeR6ivtY7svMpPyCsL6huTHpB';
try {
    const gk = await zkClient.giftCardFromCode(url);
    console.log(`This card with balance ${gk.balance} intended for ${gk.poolAlias} pool`);
} catch (err) {
    console.log(`An error was occured while parsing the gift-card: ${err.message}`);
}
// output: This card with balance 100000000000 intended for BOB-sepolia pool

Promise returns the of a decoded card. Errors may return InternalError.

GiftCardProperties
GiftCardProperties
Getting Gift Card Actual Balance
giftCardBalance(giftCard: GiftCardProperties)
redeemGiftCard(giftCard:GiftCardProperties, preferredProvingMode?: ProverMode)