0
```
//SPDX-License-Identifier:GPL-3.0

pragma solidity 0.8.13;

contract trade{

    constructor() { owner = msg. sender; }

    address owner;

    modifier onlyOwner {
        require(msg.sender == owner);
        _;

}


//////////////////////
/////required mappings

    // map consumer address to consumer userID

    mapping(address => uint32) public consumers;

    //map producer address to producerID "is a registered producer"

    mapping(address => uint) public producers;

    //map address to energy balance of the users"

    mapping(address => uint) public userEnergyBal;

///////////////////////////
//////consumer regster part

    modifier onlyRegisteredConsumers {
        require (consumers[msg. sender] > 0);
       _;
    }
    function registerConsumer (address aconsumer, uint32 auserID, uint buserEnergyBal) onlyOwner external {
        consumers [aconsumer] = auserID;
        userEnergyBal [aconsumer] = buserEnergyBal;

    }

////////////////////////////
//////producer register part

    modifier onlyRegisteredProducers {
    require (producers[msg. sender]>0);
    _;
    }
    function registerProducer(address bproducer,uint buserID, uint buserEnergyBal) onlyOwner external {
    require(buserID>0);
    producers [bproducer] = buserID;
    userEnergyBal [bproducer] = buserEnergyBal;
    }

////////////////////
////////trading part

    function buy_energy (address aproducer, uint64 aenergy) onlyRegisteredConsumers external payable {
    sendEthUser(aproducer);
    }

    function sendEthUser(address _user) public payable{
       payable(_user).transfer(2);
    }

}
```

I have tried with both test network and remix IDE virtual ID's Checked by changing the transaction amount I think the problem is with this part: but I can't figure out whats wrong

    uint256 beforeBal = userEnergyBal [msg.sender];
        userEnergyBal[aproducer] -= aenergy;
        userEnergyBal [msg.sender] += aenergy;
        require(userEnergyBal[msg.sender]-beforeBal==aenergy,"Energy is not transfered yet");

error sceenshot is here

**Ignore this part. Added, because excessive code was not permitted to submit here.

At the heart of P2P energy trading is the blockchain, a decentralized and immutable ledger that records transactions across a network of computers. This technology ensures transparency, security, and trust among participants, eliminating the need for intermediaries to validate and settle energy transactions. At the heart of P2P energy trading is the blockchain, a decentralized and immutable ledger that records transactions across a network of computers. This technology ensures transparency, security, and trust among participants, eliminating the need for intermediaries to validate and settle energy transactions.

0 Answers0