norths
Published © MIT

Accelerator for P2P smart meter contracts

Accelerator for P2P smart meter contracts

IntermediateFull instructions providedOver 6 days216
Accelerator for P2P smart meter contracts

Things used in this project

Hardware components

Varium C1100 Blockchain Accelerator Card
AMD Varium C1100 Blockchain Accelerator Card
×1

Software apps and online services

Vitis Unified Software Platform
AMD Vitis Unified Software Platform
Xilinx XRT

Story

Read more

Schematics

Core Architecture

Core Architecture

Code

PowerMeter Smart Contract DApp in solidity

JavaScript
PowerMeter Smart Contract DApp in solidity
pragma solidity 0.8.7;

contract PowerMeter {

    // Declare state variables of the contract
    address public owner;
    mapping (address => uint) public electricityBalances;

    // When 'electricity' contract is deployed:
    // 1. set the deploying address as the owner of the contract
    // 2. set the deployed smart contract's electricity balance to 100
    constructor() {
        owner = msg.sender;
        electricityBalances[address(this)] = 100;
    }

    // Allow the owner to increase the smart contract's electricity balance
    function refill(uint amount) public {
        require(msg.sender == owner, "Only the owner can refill.");
        electricityBalances[address(this)] += amount;
    }

    // Allow anyone to purchase electricity
    function purchase(uint amount) public payable {
        require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per electricity");
        require(electricityBalances[address(this)] >= amount, "Not enough electricity in stock to complete this purchase");
        electricityBalances[address(this)] -= amount;
        electricityBalances[msg.sender] += amount;
    }

Credits

norths

norths

7 projects • 2 followers
Fun explorer

Comments