Smart Contract: Transparency Storage Banking

Latar Belakang Kasus

  1. Sistem penyimpanan bank tradisional memiliki masalah seperti sentralisasi dan ketidakjelasan

  2. Melalui kontrak pintar yang ditulis dalam Solidity. kami dapat menerapkan sistem perbankan yang terdesentralisasi dan transparan memungkinkan pengguna lebih percaya dan mengandalkan sistem ini.

Desain Kontrak

Kontrak Pintar kami memiliki bagian-bagian penting berikut

  1. Management Akun Pengguna: mencacat saldo pengguna dan riwayat transaksi

  2. Fungsi Deposit: memungkinkan pengguna untuk menyetor ke akun mereka.

  3. Fungsi Penarikan: memungkinkan pengguna untuk menarik saldo dari akun mereka.

  4. Kueri Catatan Transaksi: memungkinkan pengguna menanyakan riwayat transaksi mereka.


Berikut adalah contoh kode kontrak pintar solidity untuk sistem terdesentralisasi perbankan.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract TransparentBankStorage {
    mapping(address => uint256) private balances;
    mapping(address => mapping(address => uint256)) private transactions;

    event LogDeposit(address indexed from, uint256 amount);
    event LogWithdraw(address indexed to, uint256 amount);

    function deposit() public payable {
        require(msg.value > 0, "Deposit amount must be greater than 0");
        balances[msg.sender] += msg.value;
        emit LogDeposit(msg.sender, msg.value);
    }

    function withdraw(uint256 amount) public {
        require(balances[msg.sender] >= amount, "Insufficient balance");
        balances[msg.sender] -= amount;
        payable(msg.sender).transfer(amount);
        emit LogWithdraw(msg.sender, amount);
    }

    function getBalance() public view returns (uint256) {
        return balances[msg.sender];
    }

    // Function to retrieve the transaction amount from _user to msg.sender
    function getTransaction(address _user) public view returns (uint256) {
        return transactions[_user][msg.sender];
    }

    // Function to perform a transaction from msg.sender to _user
    function performTransaction(address _user, uint256 amount) public {
        require(balances[msg.sender] >= amount, "Insufficient balance");
        balances[msg.sender] -= amount;
        balances[_user] += amount;
        transactions[msg.sender][_user] += amount;
        emit LogWithdraw(msg.sender, amount);
        emit LogDeposit(_user, amount);
    }
}
Subscribe to Avenlabs
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.