Skip to content
Verified contractPartial

EtherMango

Address0xd282aaabc2b194ebba0da2b98ef1c9c66eb24931
Balance

0.00021 ETH

 

Transactions

66

 

Compiler

solc 0.4.19

 

Same code

1 more contract

 

Details

Compiler
solc 0.4.19+commit.c4cbbb05
Language
solidity
Optimization
No
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
5,276,558
Creation transaction
0xcf26551c47…42b3c2a7af

EtherMango.sol

pragma solidity ^0.4.18;

// See ethermango.com
// Sell digital products easily, only 1% fees
contract EtherMango {
    
    uint public feePercent = 100;
    address owner;
    uint public numProducts;
    mapping(uint => Product) public products;
    mapping(address => mapping(uint => bool)) public purchases;

    event ProductAdded(uint productId, address merchant, uint price);
    event ProductPurchased(uint productId, address buyer);
    
    struct Product {
        uint price;
        address merchant;
        bool isFrozen;
    }
    
    function EtherMango() public payable {
        owner = msg.sender;
    }
    
    function AddProduct(uint price) public payable returns(uint productId) {
        productId = numProducts++;

        products[productId] = Product(price, msg.sender, false);
        // Merchant auto purchases their own product
        purchases[msg.sender][productId] = true;
        ProductAdded(productId, msg.sender, price);
    }
    
    function Pay(uint productId) public payable {
        require(products[productId].price == msg.value);
        require(products[productId].isFrozen == false);

        uint fee = msg.value / feePercent;
        uint remaining = msg.value - fee;
        // Immediately pay out merchant, but keep fees in contract
        // Which keeps the gas cost lower
        products[productId].merchant.transfer(remaining);
        
        // Log the purchase on the blockchain
        purchases[msg.sender][productId] = true;
        ProductPurchased(productId, msg.sender);
    }
    
    function WithdrawFees() public payable {
        require(msg.sender == owner);
        owner.transfer(this.balance);
    }

    function FreezeProduct(uint productId) public {
        require(products[productId].merchant == msg.sender);
        products[productId].isFrozen = true;
    }
    
    function UnFreezeProduct(uint productId) public {
        require(products[productId].merchant == msg.sender);
        products[productId].isFrozen = false;
    }
}
Compiler settingsShow
{
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.