DEV Community

rayQu
rayQu

Posted on

Building a Transparent Crypto Donation Ledger with Oasis Network (Beginner Tutorial)

Crypto donations are great for transparency… until your donors open a block explorer and see a wall of hashes.

In this tutorial, we’ll build a simple, verifiable donation ledger using Oasis Network, a blockchain that lets you combine privacy + transparency using confidential smart contracts.


What we’re building

A minimal system where:

  • Donations are recorded on-chain
  • Expenses are recorded and linked to donations
  • Anyone can see totals and categories (public)
  • Sensitive details stay private but provable

Why Oasis?

With Oasis Sapphire (its confidential EVM):

  • You write Solidity like Ethereum
  • But contract state can be encrypted
  • You can expose only what matters (e.g. totals)

Docs: https://docs.oasis.io
Sapphire: https://oasis.net/sapphire


Step 1: Setup your environment

You can use Hardhat like a normal EVM chain:

mkdir oasis-ledger && cd oasis-ledger
npm init -y
npm install --save-dev hardhat
npx hardhat
Enter fullscreen mode Exit fullscreen mode

Add Oasis Sapphire testnet config:

module.exports = {
  networks: {
    sapphire: {
      url: "https://testnet.sapphire.oasis.io",
      accounts: [PRIVATE_KEY]
    }
  },
  solidity: "0.8.20"
};
Enter fullscreen mode Exit fullscreen mode

Step 2: Write the smart contract

Create DonationLedger.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract DonationLedger {

    struct Donation {
        address donor;
        uint amount;
    }

    struct Expense {
        uint amount;
        string category;
    }

    Donation[] public donations;
    Expense[] public expenses;

    uint public totalDonations;
    uint public totalSpent;

    function donate() external payable {
        donations.push(Donation(msg.sender, msg.value));
        totalDonations += msg.value;
    }

    function addExpense(uint _amount, string memory _category) external {
        expenses.push(Expense(_amount, _category));
        totalSpent += _amount;
    }

    function getBalance() public view returns (uint) {
        return totalDonations - totalSpent;
    }
}
Enter fullscreen mode Exit fullscreen mode

This is intentionally simple:

  • Fully transparent totals
  • Expand later with private metadata (Oasis advantage)

Step 3: Deploy to Oasis Sapphire

Create a deploy script:

async function main() {
  const Ledger = await ethers.getContractFactory("DonationLedger");
  const ledger = await Ledger.deploy();

  await ledger.waitForDeployment();

  console.log("Deployed to:", await ledger.getAddress());
}

main();
Enter fullscreen mode Exit fullscreen mode

Run:

npx hardhat run scripts/deploy.js --network sapphire
Enter fullscreen mode Exit fullscreen mode

Step 4: Interact with the contract

Example (Hardhat console):

npx hardhat console --network sapphire
Enter fullscreen mode Exit fullscreen mode
const ledger = await ethers.getContractAt("DonationLedger", "DEPLOYED_ADDRESS");

// donate
await ledger.donate({ value: ethers.parseEther("0.1") });

// add expense
await ledger.addExpense(ethers.parseEther("0.05"), "food");

// check totals
await ledger.totalDonations();
await ledger.totalSpent();
Enter fullscreen mode Exit fullscreen mode

Step 5: Build a simple frontend (optional)

Even a basic UI can transform usability:

  • Show:

    • Total donations
    • Total spent
    • Remaining balance
  • Add buttons:

    • “Donate”
    • “Add Expense” (admin)

You can use:

  • Next.js
  • ethers.js
  • wagmi

Step 6: Where Oasis shines (upgrade idea)

Right now everything is public.

With Oasis, you can:

  • Store private expense metadata (e.g. invoice hashes)
  • Keep donor notes confidential
  • Reveal only:

    • totals
    • categories
    • proofs

This is done using confidential state inside Sapphire contracts.


Final result

Instead of showing donors this:

“Here’s our wallet, go check Etherscan”

You show them:

  • €100k raised
  • €40k spent on food
  • €20k spent on shelter

And every number is still verifiable on-chain


Takeaway

Using Oasis, you can build:

  • Transparent donation systems
  • Clean public dashboards
  • Private but provable accounting

All without leaving the EVM ecosystem.


Resources

Top comments (0)