false
false

Contract Address Details

0xFD7b100CF65af83dc7C81F73511cBC4f4192617F

Contract Name
cityHealth
Creator
0x864f78–c6436b at 0x8cff1e–bf107c
Balance
0
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
15260241
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
cityHealth




Optimization enabled
true
Compiler version
v0.8.0+commit.c7dfd78e




Optimization runs
200
EVM Version
default




Verified at
2024-09-12T09:32:23.486374Z

Contract source code

Sol2uml
new
pragma solidity ^0.8.0;

contract cityHealth {
    struct Project {
        string name;
        uint256 carbonCredits;
        bool active;
        address owner;
    }

    struct CreditTransaction {
        uint256 amount;
        address from;
        address to;
        uint256 timestamp;
    }

    address public cityAdmin;
    mapping(uint256 => Project) public projects;
    mapping(address => uint256) public carbonCreditsBalance;
    mapping(uint256 => CreditTransaction[]) public projectTransactions;
    uint256 public projectCount;
    uint256 public totalCarbonCredits;

    event ProjectRegistered(uint256 indexed projectId, string name, address owner);
    event CarbonCreditsIssued(uint256 indexed projectId, uint256 amount);
    event CarbonCreditsTransferred(address indexed from, address indexed to, uint256 amount);
    event ProjectStatusChanged(uint256 indexed projectId, bool active);

    modifier onlyCityAdmin() {
        require(msg.sender == cityAdmin, "Only city admin can call this function");
        _;
    }

    modifier onlyProjectOwner(uint256 _projectId) {
        require(msg.sender == projects[_projectId].owner, "Only project owner can call this function");
        _;
    }

    constructor() {
        cityAdmin = msg.sender;
    }

    function registerProject(string memory _name, address _owner) public onlyCityAdmin {
        projectCount++;
        projects[projectCount] = Project(_name, 0, true, _owner);
        emit ProjectRegistered(projectCount, _name, _owner);
    }

    function issueCarbonCredits(uint256 _projectId, uint256 _amount) public onlyCityAdmin {
        require(projects[_projectId].active, "Project is not active");
        projects[_projectId].carbonCredits += _amount;
        carbonCreditsBalance[projects[_projectId].owner] += _amount;
        totalCarbonCredits += _amount;
        
        projectTransactions[_projectId].push(CreditTransaction(_amount, address(0), projects[_projectId].owner, block.timestamp));
        
        emit CarbonCreditsIssued(_projectId, _amount);
    }

    function transferCarbonCredits(address _to, uint256 _amount) public {
        require(carbonCreditsBalance[msg.sender] >= _amount, "Insufficient carbon credits");
        carbonCreditsBalance[msg.sender] -= _amount;
        carbonCreditsBalance[_to] += _amount;
        
        emit CarbonCreditsTransferred(msg.sender, _to, _amount);
    }

    function changeProjectStatus(uint256 _projectId, bool _active) public onlyCityAdmin {
        projects[_projectId].active = _active;
        emit ProjectStatusChanged(_projectId, _active);
    }

    function getProjectDetails(uint256 _projectId) public view returns (string memory, uint256, bool, address) {
        Project memory project = projects[_projectId];
        return (project.name, project.carbonCredits, project.active, project.owner);
    }

    function getProjectTransactions(uint256 _projectId) public view returns (CreditTransaction[] memory) {
        return projectTransactions[_projectId];
    }

    function getCarbonCreditsBalance(address _address) public view returns (uint256) {
        return carbonCreditsBalance[_address];
    }

    function getTotalCarbonCredits() public view returns (uint256) {
        return totalCarbonCredits;
    }

    function calculateCarbonOffset(uint256 _projectId) public view returns (uint256) {
        // This is a placeholder function. In a real-world scenario, this would involve
        // complex calculations based on project type, duration, and other factors.
        return projects[_projectId].carbonCredits;
    }
}
        

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"CarbonCreditsIssued","inputs":[{"type":"uint256","name":"projectId","internalType":"uint256","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"CarbonCreditsTransferred","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"ProjectRegistered","inputs":[{"type":"uint256","name":"projectId","internalType":"uint256","indexed":true},{"type":"string","name":"name","internalType":"string","indexed":false},{"type":"address","name":"owner","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"ProjectStatusChanged","inputs":[{"type":"uint256","name":"projectId","internalType":"uint256","indexed":true},{"type":"bool","name":"active","internalType":"bool","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"calculateCarbonOffset","inputs":[{"type":"uint256","name":"_projectId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"carbonCreditsBalance","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"changeProjectStatus","inputs":[{"type":"uint256","name":"_projectId","internalType":"uint256"},{"type":"bool","name":"_active","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"cityAdmin","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getCarbonCreditsBalance","inputs":[{"type":"address","name":"_address","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bool","name":"","internalType":"bool"},{"type":"address","name":"","internalType":"address"}],"name":"getProjectDetails","inputs":[{"type":"uint256","name":"_projectId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct cityHealth.CreditTransaction[]","components":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]}],"name":"getProjectTransactions","inputs":[{"type":"uint256","name":"_projectId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTotalCarbonCredits","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"issueCarbonCredits","inputs":[{"type":"uint256","name":"_projectId","internalType":"uint256"},{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"projectCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"timestamp","internalType":"uint256"}],"name":"projectTransactions","inputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"name","internalType":"string"},{"type":"uint256","name":"carbonCredits","internalType":"uint256"},{"type":"bool","name":"active","internalType":"bool"},{"type":"address","name":"owner","internalType":"address"}],"name":"projects","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"registerProject","inputs":[{"type":"string","name":"_name","internalType":"string"},{"type":"address","name":"_owner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalCarbonCredits","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferCarbonCredits","inputs":[{"type":"address","name":"_to","internalType":"address"},{"type":"uint256","name":"_amount","internalType":"uint256"}]}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610e89806100326000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80637f74558511610097578063be7fe8eb11610066578063be7fe8eb146101d2578063c0c55b17146101e7578063c9b6f53914610207578063fc1ce66c1461021a576100f5565b80637f7455851461019c578063811b6baf146101af578063adebbd5b146101b7578063afcdd813146101bf576100f5565b80634c9bda4b116100d35780634c9bda4b146101505780634d8d476b146101635780635f8439e314610176578063641e401e14610189576100f5565b8063107046bd146100fa57806336a09b7d1461012657806336fbad261461013b575b600080fd5b61010d610108366004610b20565b61023d565b60405161011d9493929190610c90565b60405180910390f35b610139610134366004610a6e565b6102fa565b005b61014361041b565b60405161011d9190610d74565b61014361015e366004610b20565b610421565b610139610171366004610b6b565b61043a565b61010d610184366004610b20565b6105e7565b610143610197366004610a24565b6106f5565b6101396101aa366004610b38565b610707565b610143610780565b610143610786565b6101396101cd366004610a45565b61078c565b6101da610855565b60405161011d9190610bd7565b6101fa6101f5366004610b20565b610864565b60405161011d9190610beb565b610143610215366004610a24565b610904565b61022d610228366004610b6b565b61091f565b60405161011d9493929190610d7d565b60016020526000908152604090208054819061025890610dd1565b80601f016020809104026020016040519081016040528092919081815260200182805461028490610dd1565b80156102d15780601f106102a6576101008083540402835291602001916102d1565b820191906000526020600020905b8154815290600101906020018083116102b457829003601f168201915b50505050600183015460029093015491929160ff8116915061010090046001600160a01b031684565b6000546001600160a01b0316331461032d5760405162461bcd60e51b815260040161032490610cc8565b60405180910390fd5b6004805490600061033d83610e0c565b9091555050604080516080810182528381526000602080830182905260018385018190526001600160a01b038616606085015260045483528152929020815180519293919261038f9284920190610974565b5060208201516001820155604080830151600290920180546060909401516001600160a01b031661010002610100600160a81b031993151560ff19909516949094179290921692909217905560045490517fbe67d123666fdaa12bddfaf9f13056f83522df7149a1717d7ba91baf586cfcc89061040f9085908590610c66565b60405180910390a25050565b60045481565b600081815260016020819052604090912001545b919050565b6000546001600160a01b031633146104645760405162461bcd60e51b815260040161032490610cc8565b60008281526001602052604090206002015460ff166104955760405162461bcd60e51b815260040161032490610d0e565b600082815260016020819052604082200180548392906104b6908490610da2565b9091555050600082815260016020908152604080832060029081015461010090046001600160a01b03168452909152812080548392906104f7908490610da2565b9250508190555080600560008282546105109190610da2565b90915550506000828152600360208181526040808420815160808101835286815280840186815288875260018086528488206002908101546001600160a01b036101009091048116858801908152426060870190815287548086018955978c5298909a2094516004909602909401948555915190840180546001600160a01b031990811692851692909217905596519083018054909716911617909455905192909101919091555182907f8baee305f50c5b362ef7307e16ce731e36cf223b95e0c51f3c43c5f2bac3d49f9061040f908490610d74565b60606000806000806001600087815260200190815260200160002060405180608001604052908160008201805461061d90610dd1565b80601f016020809104026020016040519081016040528092919081815260200182805461064990610dd1565b80156106965780601f1061066b57610100808354040283529160200191610696565b820191906000526020600020905b81548152906001019060200180831161067957829003601f168201915b5050509183525050600182015460208083019190915260029092015460ff811615156040808401919091526101009091046001600160a01b03166060928301528351928401519084015193909101519199909850919650945092505050565b60026020526000908152604090205481565b6000546001600160a01b031633146107315760405162461bcd60e51b815260040161032490610cc8565b60008281526001602052604090819020600201805460ff19168315151790555182907f73c9860341fcf3a75820bf92ceafc9c352f5590f6693cd99123378b454372b7d9061040f908490610c5b565b60055490565b60055481565b336000908152600260205260409020548111156107bb5760405162461bcd60e51b815260040161032490610d3d565b33600090815260026020526040812080548392906107da908490610dba565b90915550506001600160a01b03821660009081526002602052604081208054839290610807908490610da2565b90915550506040516001600160a01b0383169033907f4bddcd2adcae63181f5513ae0e14ae39dfd81f5d7f840faca9b8ce46caf7f77d90610849908590610d74565b60405180910390a35050565b6000546001600160a01b031681565b606060036000838152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b828210156108f95760008481526020908190206040805160808101825260048602909201805483526001808201546001600160a01b0390811685870152600283015416928401929092526003015460608301529083529092019101610899565b505050509050919050565b6001600160a01b031660009081526002602052604090205490565b6003602052816000526040600020818154811061093b57600080fd5b600091825260209091206004909102018054600182015460028301546003909301549194506001600160a01b0390811693509091169084565b82805461098090610dd1565b90600052602060002090601f0160209004810192826109a257600085556109e8565b82601f106109bb57805160ff19168380011785556109e8565b828001600101855582156109e8579182015b828111156109e85782518255916020019190600101906109cd565b506109f49291506109f8565b5090565b5b808211156109f457600081556001016109f9565b80356001600160a01b038116811461043557600080fd5b600060208284031215610a35578081fd5b610a3e82610a0d565b9392505050565b60008060408385031215610a57578081fd5b610a6083610a0d565b946020939093013593505050565b60008060408385031215610a80578182fd5b823567ffffffffffffffff80821115610a97578384fd5b818501915085601f830112610aaa578384fd5b8135602082821115610abe57610abe610e3d565b604051601f8301601f1916810182018481118282101715610ae157610ae1610e3d565b6040528281528483018201891015610af7578687fd5b8282860183830137808301820196909652610b13878201610a0d565b9450505050509250929050565b600060208284031215610b31578081fd5b5035919050565b60008060408385031215610b4a578182fd5b8235915060208301358015158114610b60578182fd5b809150509250929050565b60008060408385031215610b7d578182fd5b50508035926020909101359150565b60008151808452815b81811015610bb157602081850181015186830182015201610b95565b81811115610bc25782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b0391909116815260200190565b602080825282518282018190526000919060409081850190868401855b82811015610c4e57815180518552868101516001600160a01b03908116888701528682015116868601526060908101519085015260809093019290850190600101610c08565b5091979650505050505050565b901515815260200190565b600060408252610c796040830185610b8c565b905060018060a01b03831660208301529392505050565b600060808252610ca36080830187610b8c565b60208301959095525091151560408301526001600160a01b0316606090910152919050565b60208082526026908201527f4f6e6c7920636974792061646d696e2063616e2063616c6c20746869732066756040820152653731ba34b7b760d11b606082015260800190565b60208082526015908201527450726f6a656374206973206e6f742061637469766560581b604082015260600190565b6020808252601b908201527f496e73756666696369656e7420636172626f6e20637265646974730000000000604082015260600190565b90815260200190565b9384526001600160a01b03928316602085015291166040830152606082015260800190565b60008219821115610db557610db5610e27565b500190565b600082821015610dcc57610dcc610e27565b500390565b600281046001821680610de557607f821691505b60208210811415610e0657634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415610e2057610e20610e27565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fdfea264697066735822122094e513609cff8f1c8dc8dd46990148fb00e2152a6c2d052fb4dd23877b7a5f1564736f6c63430008000033

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80637f74558511610097578063be7fe8eb11610066578063be7fe8eb146101d2578063c0c55b17146101e7578063c9b6f53914610207578063fc1ce66c1461021a576100f5565b80637f7455851461019c578063811b6baf146101af578063adebbd5b146101b7578063afcdd813146101bf576100f5565b80634c9bda4b116100d35780634c9bda4b146101505780634d8d476b146101635780635f8439e314610176578063641e401e14610189576100f5565b8063107046bd146100fa57806336a09b7d1461012657806336fbad261461013b575b600080fd5b61010d610108366004610b20565b61023d565b60405161011d9493929190610c90565b60405180910390f35b610139610134366004610a6e565b6102fa565b005b61014361041b565b60405161011d9190610d74565b61014361015e366004610b20565b610421565b610139610171366004610b6b565b61043a565b61010d610184366004610b20565b6105e7565b610143610197366004610a24565b6106f5565b6101396101aa366004610b38565b610707565b610143610780565b610143610786565b6101396101cd366004610a45565b61078c565b6101da610855565b60405161011d9190610bd7565b6101fa6101f5366004610b20565b610864565b60405161011d9190610beb565b610143610215366004610a24565b610904565b61022d610228366004610b6b565b61091f565b60405161011d9493929190610d7d565b60016020526000908152604090208054819061025890610dd1565b80601f016020809104026020016040519081016040528092919081815260200182805461028490610dd1565b80156102d15780601f106102a6576101008083540402835291602001916102d1565b820191906000526020600020905b8154815290600101906020018083116102b457829003601f168201915b50505050600183015460029093015491929160ff8116915061010090046001600160a01b031684565b6000546001600160a01b0316331461032d5760405162461bcd60e51b815260040161032490610cc8565b60405180910390fd5b6004805490600061033d83610e0c565b9091555050604080516080810182528381526000602080830182905260018385018190526001600160a01b038616606085015260045483528152929020815180519293919261038f9284920190610974565b5060208201516001820155604080830151600290920180546060909401516001600160a01b031661010002610100600160a81b031993151560ff19909516949094179290921692909217905560045490517fbe67d123666fdaa12bddfaf9f13056f83522df7149a1717d7ba91baf586cfcc89061040f9085908590610c66565b60405180910390a25050565b60045481565b600081815260016020819052604090912001545b919050565b6000546001600160a01b031633146104645760405162461bcd60e51b815260040161032490610cc8565b60008281526001602052604090206002015460ff166104955760405162461bcd60e51b815260040161032490610d0e565b600082815260016020819052604082200180548392906104b6908490610da2565b9091555050600082815260016020908152604080832060029081015461010090046001600160a01b03168452909152812080548392906104f7908490610da2565b9250508190555080600560008282546105109190610da2565b90915550506000828152600360208181526040808420815160808101835286815280840186815288875260018086528488206002908101546001600160a01b036101009091048116858801908152426060870190815287548086018955978c5298909a2094516004909602909401948555915190840180546001600160a01b031990811692851692909217905596519083018054909716911617909455905192909101919091555182907f8baee305f50c5b362ef7307e16ce731e36cf223b95e0c51f3c43c5f2bac3d49f9061040f908490610d74565b60606000806000806001600087815260200190815260200160002060405180608001604052908160008201805461061d90610dd1565b80601f016020809104026020016040519081016040528092919081815260200182805461064990610dd1565b80156106965780601f1061066b57610100808354040283529160200191610696565b820191906000526020600020905b81548152906001019060200180831161067957829003601f168201915b5050509183525050600182015460208083019190915260029092015460ff811615156040808401919091526101009091046001600160a01b03166060928301528351928401519084015193909101519199909850919650945092505050565b60026020526000908152604090205481565b6000546001600160a01b031633146107315760405162461bcd60e51b815260040161032490610cc8565b60008281526001602052604090819020600201805460ff19168315151790555182907f73c9860341fcf3a75820bf92ceafc9c352f5590f6693cd99123378b454372b7d9061040f908490610c5b565b60055490565b60055481565b336000908152600260205260409020548111156107bb5760405162461bcd60e51b815260040161032490610d3d565b33600090815260026020526040812080548392906107da908490610dba565b90915550506001600160a01b03821660009081526002602052604081208054839290610807908490610da2565b90915550506040516001600160a01b0383169033907f4bddcd2adcae63181f5513ae0e14ae39dfd81f5d7f840faca9b8ce46caf7f77d90610849908590610d74565b60405180910390a35050565b6000546001600160a01b031681565b606060036000838152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b828210156108f95760008481526020908190206040805160808101825260048602909201805483526001808201546001600160a01b0390811685870152600283015416928401929092526003015460608301529083529092019101610899565b505050509050919050565b6001600160a01b031660009081526002602052604090205490565b6003602052816000526040600020818154811061093b57600080fd5b600091825260209091206004909102018054600182015460028301546003909301549194506001600160a01b0390811693509091169084565b82805461098090610dd1565b90600052602060002090601f0160209004810192826109a257600085556109e8565b82601f106109bb57805160ff19168380011785556109e8565b828001600101855582156109e8579182015b828111156109e85782518255916020019190600101906109cd565b506109f49291506109f8565b5090565b5b808211156109f457600081556001016109f9565b80356001600160a01b038116811461043557600080fd5b600060208284031215610a35578081fd5b610a3e82610a0d565b9392505050565b60008060408385031215610a57578081fd5b610a6083610a0d565b946020939093013593505050565b60008060408385031215610a80578182fd5b823567ffffffffffffffff80821115610a97578384fd5b818501915085601f830112610aaa578384fd5b8135602082821115610abe57610abe610e3d565b604051601f8301601f1916810182018481118282101715610ae157610ae1610e3d565b6040528281528483018201891015610af7578687fd5b8282860183830137808301820196909652610b13878201610a0d565b9450505050509250929050565b600060208284031215610b31578081fd5b5035919050565b60008060408385031215610b4a578182fd5b8235915060208301358015158114610b60578182fd5b809150509250929050565b60008060408385031215610b7d578182fd5b50508035926020909101359150565b60008151808452815b81811015610bb157602081850181015186830182015201610b95565b81811115610bc25782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b0391909116815260200190565b602080825282518282018190526000919060409081850190868401855b82811015610c4e57815180518552868101516001600160a01b03908116888701528682015116868601526060908101519085015260809093019290850190600101610c08565b5091979650505050505050565b901515815260200190565b600060408252610c796040830185610b8c565b905060018060a01b03831660208301529392505050565b600060808252610ca36080830187610b8c565b60208301959095525091151560408301526001600160a01b0316606090910152919050565b60208082526026908201527f4f6e6c7920636974792061646d696e2063616e2063616c6c20746869732066756040820152653731ba34b7b760d11b606082015260800190565b60208082526015908201527450726f6a656374206973206e6f742061637469766560581b604082015260600190565b6020808252601b908201527f496e73756666696369656e7420636172626f6e20637265646974730000000000604082015260600190565b90815260200190565b9384526001600160a01b03928316602085015291166040830152606082015260800190565b60008219821115610db557610db5610e27565b500190565b600082821015610dcc57610dcc610e27565b500390565b600281046001821680610de557607f821691505b60208210811415610e0657634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415610e2057610e20610e27565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fdfea264697066735822122094e513609cff8f1c8dc8dd46990148fb00e2152a6c2d052fb4dd23877b7a5f1564736f6c63430008000033