0

This is my code

pragma solidity ^0.4.19;

contract FirstContract
{
    address creator;
    uint256 priceOfATransaction = msg.value;
    uint256 totalAmount;
    address buyer;

    function FirstContract() public
    {
        creator = msg.sender;
    }

    function perSaleDetails() public
    {
        totalAmount += priceOfATransaction;
        //=========Detail of an order==========//
        priceOfATransaction = 0;
    }

    function sellerMoneey() public returns(bool)
    {
        if(msg.sender == creator){
            if(!creator.send(totalAmount)) {
                return false;
            }
        }
    }
}

REMIX WARNING:-

Gas requirement of function FirstContract.sellerMoneey() high: infinite. If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage)

What do I need to modify

  • This may a bug in remix. It can not estimate gas for even simple function. – Prashant Prabhakar Singh Jan 29 '18 at 13:07
0

Any use of send() and transfer() usually throws that compiler warning on REMIX even if there isn't loops or storage changes.

I assume you are just getting started with solidity and smart contracts, so there are a few things you will learn moving forward. Especially with lines like uint256 priceOfATransaction = msg.value;.

Your code is safe to compile.

  • Thanks. But my contract is deployed. What I am trying to figure out is everytime I send some ether to the contract it doesn't complete the transaction and fails. Can you suggest a code that accepts the ether and then sends it to another address. Thanks in advance. – Agnish Chakraborty Jan 29 '18 at 13:00
  • 1
    @AgnishChakraborty Well, that's a totally different question...but none of your functions are payable. Without that, your contract is reverted. You need a payable method in order to receive anything int he contract. – ReyHaynes Jan 29 '18 at 13:19
  • @AgnishChakraborty secondly, this makes the line I mentioned even more of an issue since the priceOfATransaction is set to msg.value only once when the contract is created. – ReyHaynes Jan 29 '18 at 13:22
  • @AgnishChakraborty I'd help you with the code, but honestly, I have no clue what you're trying to accomplish with the state of the code initially. If you explain each function a bit more, I can help. – ReyHaynes Jan 29 '18 at 13:24
  • I want a contract that can accept ether. Has two functions that can calculate some variables passed. And a function to send the balance to the creator. – Agnish Chakraborty Jan 30 '18 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.