← ALL POSTS
9 NOVEMBER 2025

Building Blockchain Transparency: Prize Draw Integration with Arbitrum & Chainlink VRF

Date Completed: November 8, 2025
Build Status: ✅ Code Complete - 7/7 Smart Contract Tests Passing
Transaction Cost: ~$5 per draw on Arbitrum One

What We Built

We’ve completed a full blockchain integration for the AIVA Platform that makes our prize draws provably fair and publicly verifiable. This isn’t just a buzzword - every entry, every transaction, and every winner is recorded on the Arbitrum blockchain where anyone can verify the results.

The Tech Stack

  • Arbitrum One - Ethereum Layer 2 for low-cost transactions (~$0.05-$0.20 per complete draw)
  • Chainlink VRF V2.5 - Decentralized random number generation for provably fair winner selection
  • Solidity Smart Contract - PrizeDraw.sol with weighted entry system and lifecycle management
  • Nethereum (C#) - Full Web3 integration for our .NET backend
  • Foundry - Smart contract testing framework (7/7 tests passing)

How It Works

1. Create Draw on Blockchain

When a prize draw is created, we submit it to the blockchain with name, description, start time, and end time. The blockchain returns a unique draw ID and transaction hash that anyone can verify on Arbiscan.

2. Weighted Entry System

Not all entries are equal. Our smart contract supports different entry weights:

  • Purchase - 1 entry per $10 spent
  • Referral Signup - 5 entries
  • Referral Purchase - 10 entries
  • Social Share - 2 entries
  • Direct Entry - 1 entry

3. Provably Fair Winner Selection

This is where Chainlink VRF comes in. When it’s time to select a winner:

  1. We close the draw on-chain
  2. Request a random number from Chainlink VRF
  3. Chainlink’s decentralized oracles generate a verifiable random number
  4. Smart contract uses binary search to select winner based on weighted entries
  5. Winner is recorded with their Shopify customer ID
  6. Background service automatically detects the WinnerSelected event
  7. Database is updated with winner information

Why This Matters: No one - not even us - can manipulate the results. The random number is cryptographically verifiable, and the entire selection process is transparent on the blockchain.

Technical Implementation

Smart Contract (Solidity)

Our PrizeDraw.sol contract includes:

  • Draw lifecycle management (Active → Closed → Drawn → Cancelled)
  • Weighted entry accumulation with efficient binary search
  • Chainlink VRF integration for randomness
  • Public verification functions (anyone can check entries and probabilities)
  • Comprehensive event logging for transparency

Backend Service (C# / .NET 9)

Our BlockchainService.cs provides:

  • Full Web3 integration via Nethereum
  • Automatic gas estimation and transaction confirmation
  • Private key encryption using Data Protection API
  • Background event listener for automatic winner detection
  • Comprehensive error handling and retry logic
  • Structured logging with Serilog (no sensitive data)

Security Measures

  • Private Key Encryption: All blockchain wallet private keys are encrypted using Microsoft Data Protection API
  • Secure Key Storage: Encryption keys stored outside application directory
  • No Logs of Sensitive Data: Private keys never appear in logs
  • Dedicated Wallet: Separate wallet used only for draw operations
  • Minimal Funding: Wallet funded with just enough ETH for operations

Cost & Performance

Transaction Costs (Arbitrum One Mainnet):

  • Create Draw: ~$0.01 - $0.10
  • Add Entry: ~$0.007 - $0.07
  • Close Draw: ~$0.003 - $0.03
  • Select Winner: ~$0.014 - $0.14
  • Chainlink VRF: ~$5 (0.25 LINK)

Total Cost Per Draw: ~$5.03 - $5.34

This is remarkably cheap for full blockchain transparency and provably fair randomness. Compare this to traditional lottery systems that cost thousands to audit.

Public Verification

Anyone can verify our draws on Arbiscan:

  • View Draw Details: See all draw parameters (name, dates, status)
  • Check Entries: View complete list of entries with weights
  • Calculate Win Probability: Query exact odds for any participant
  • Verify Random Seed: Check the Chainlink VRF random number used
  • Audit Transaction History: Full transaction log on public blockchain

What’s Next

Deployment Steps:

  1. Deploy PrizeDraw.sol to Arbitrum Sepolia testnet (FREE)
  2. Create Chainlink VRF subscription and fund with LINK
  3. Configure backend with contract address and encrypted keys
  4. Test full draw lifecycle on testnet
  5. Deploy to Arbitrum One mainnet for production

Future Enhancements:

  • Batch entry submission (reduce gas by 80%)
  • Entry Merkle trees (reduce gas by 90%)
  • Cross-chain deployment (Ethereum, Polygon)
  • NFT prize minting
  • DAO governance for draw parameters

Key Files

  • /contracts/prize-draw/src/PrizeDraw.sol - Smart contract (565 lines)
  • /contracts/prize-draw/test/PrizeDraw.t.sol - Tests (7/7 passing)
  • /src/AivaMiddleware/Services/BlockchainService.cs - C# integration (658 lines)
  • /src/AivaMiddleware/Services/BlockchainEventListenerService.cs - Event listener
  • /src/AivaMiddleware/Tools/EncryptPrivateKey.cs - Key encryption utility

Summary

We’ve built a production-ready blockchain integration that provides:

  • ✅ Provably fair winner selection via Chainlink VRF
  • ✅ Public verifiability on Arbitrum blockchain
  • ✅ Low transaction costs (~$5 per draw)
  • ✅ Complete security (encrypted keys, no sensitive logs)
  • ✅ Automatic winner detection via background service
  • ✅ 7/7 smart contract tests passing

This is a major milestone that sets us apart from every other prize draw platform. True transparency isn’t marketing - it’s code on the blockchain that anyone can verify.

Time to Deploy: ~30 minutes
Cost to Deploy: FREE on testnet, ~$20 on mainnet

Want this working on your store? Aiva does the sales, marketing and service work - in your voice, around the clock.
Get Aiva