From b6a04244e47dcd391bec05763bed37365f81ece5 Mon Sep 17 00:00:00 2001 From: Kapten boneng Date: Wed, 2 Oct 2024 19:36:08 +0700 Subject: [PATCH] Create Identity.sol: Langkah instalasi: npm install -g truffle npm install -g ganache-cli 2. Smart Contract di Solidity Buat direktori proyek dan inisialisasi Truffle: mkdir identity-dapp cd identity-dapp truffle init --- .../Identity.sol: | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Buat smart contract di direktori contracts/Identity.sol: diff --git a/Buat smart contract di direktori contracts/Identity.sol: b/Buat smart contract di direktori contracts/Identity.sol: new file mode 100644 index 0000000..1e5f880 --- /dev/null +++ b/Buat smart contract di direktori contracts/Identity.sol: @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract Identity { + struct User { + string name; + uint256 dob; // Date of Birth + string nationality; + bool isRegistered; + } + + mapping(address => User) public users; + + function register(string memory _name, uint256 _dob, string memory _nationality) public { + require(!users[msg.sender].isRegistered, "User is already registered."); + users[msg.sender] = User(_name, _dob, _nationality, true); + } + + function getUser(address _user) public view returns (string memory, uint256, string memory) { + require(users[_user].isRegistered, "User not registered."); + User memory user = users[_user]; + return (user.name, user.dob, user.nationality); + } +}