Testing Smart Contracts with Remix: Revenue Sharing Contract

·

Introduction to Remix

Remix is Ethereum's official online Integrated Development Environment (IDE). It offers robust features for smart contract development, including:

This guide explores a Revenue Sharing Contract—a classic Ethereum smart contract—and walks you through testing it on Remix.

👉 Master smart contract testing with Remix


Part 1: Revenue Sharing Contract Explained

Key Concept

The Revenue Sharing Contract allocates funds proportionally among predefined addresses. Participants can send funds to the contract, which distributes them equally (or unequally) to registered addresses.

Contract Versions

Originally from Blockchain Applications: A Hands-On Approach (Bahga & Madisetti), the contract was updated from Solidity v0.4.8 to v0.5.11 to align with modern standards.

Key Differences:


Part 2: Testing the Contract in Remix

Step 1: Compile the Contract

  1. Open Remix IDE.
  2. Paste the contract code into a new .sol file.
  3. Select the Solidity compiler (v0.5.11+).
  4. Click Compile and review:

    • Bytecode
    • ABI
    • Web3 Deploy details

Step 2: Deploy to JavaScript VM

  1. Navigate to Deploy & Run Transactions.
  2. Set:

    • Environment: JavaScript VM
    • Gas Limit: Default (no adjustment needed)
    • Value: 0 (unless testing fund transfers)
  3. Input constructor arguments (e.g., recipient addresses):

    ["0xCA35b7d...", "0x14723A0...", "0x4B0897b..."]
  4. Click Deploy.

Part 3: Interacting with the Deployed Contract

Actions:

Expected Outcome:


FAQ Section

Q1: Why use Remix over other IDEs?

A: Remix offers built-in testing tools, no local setup, and direct blockchain integration for beginners.

Q2: How do I debug compilation errors?

A: Check Solidity version compatibility and update syntax (e.g., address payable in v0.5.0+).

Q3: Can I modify distribution ratios?

A: Yes! Adjust the constructor or function logic to weight specific addresses.

👉 Explore advanced smart contract techniques


Key Takeaways


References