DEV Community

Cover image for Mastering Solidity Data Types: A Comprehensive Guide for Smart Contract Developers
CryptoWorld
CryptoWorld

Posted on

Mastering Solidity Data Types: A Comprehensive Guide for Smart Contract Developers

Original Blog Consider a decentralized exchange (DEX) contract, a prime example of where the address type comes into play. In a DEX, users deposit funds into the contract's addresses to initiate trades. The contract's logic governs the execution of trades and ensures that users' balances are updated accordingly.

contract DecentralizedExchange {
    mapping(address => uint256) public balances;

    function deposit() public payable {
        balances[msg.sender] += msg.value;
    }

    function trade(address recipient, uint256 amount) public {
        require(balances[msg.sender] >= amount, "Insufficient balance");
        balances[msg.sender] -= amount;
        balances[recipient] += amount;
    }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)