0

I've deployed my smart contract to Rinkeby test net. The "addProject" function works fine.

But when I try the "addProjectFile" function I got error.

"Error: gas required exceeds allowance or always failing transaction"

The code:

pragma solidity ^0.4.18;

contract MyProjectManger {
  address public owner;
  mapping (uint => MyProject) public myProjects;

  uint projectIndex;
  mapping (uint => uint) public projectFileIndexes;

  struct File {
    string url;
    string fileHash;
  }

  struct MyProject {
    bytes32 id;
    string name;
    mapping (uint => File) projectFiles;
  }

  function MyProjectManger() public {
    owner = msg.sender;
  }

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

  function addProject(bytes32 id, string name) public onlyOwner returns(uint projectId) {
    projectId = projectIndex;    
    myProjects[projectIndex] = MyProject(id, name);
    projectIndex++;
  }

  function addProjectFile(string url, string fileHash, uint projectKey) public onlyOwner returns(uint fileId) {
    uint projectFileIndex = projectFileIndexes[projectKey];
    MyProject storage project = myProjects[projectIndex];    
    require(project.id[0] != 0);

    fileId = projectFileIndex;
    project.projectFiles[projectFileIndex] = File(url, fileHash);    
    projectFileIndex++;
  }

  function remove() onlyOwner public {
      selfdestruct(msg.sender);
  }

  // to receive ether
  function() payable public { }

}

I did get "Gas requirement of functions" warnings for those two addXXX functions. But I don't understand, I don't have loops in those two functions, why gas requirement should be an issue?

4
  • I was able to deploy the contract. Not sure what your gas limit hit was, but make sure to set your gas limit to 600k. ropsten.etherscan.io/tx/…
    – ReyHaynes
    Mar 16, 2018 at 3:08
  • @ReyHaynes, thanks. It did deploy. But I can't call one of the function... I've updated the question. Mar 16, 2018 at 7:11
  • You're not storing the id correctly, the code breaks on the require inside the addProjectFile function.
    – Gabe
    Mar 16, 2018 at 9:24
  • @Gabe, I changed that line to "require(project.id[0] != 0);" but same result.... Mar 16, 2018 at 9:33

1 Answer 1

0

There is no error/mistake in the contract. Try compiling the contract again.

FYI, I tried deploying the contract and it was successfully deployed at https://rinkeby.etherscan.io/address/0x94677eac807ccd5fd1f686d687c3cf47ada3b97d#code

1
  • It did deploy. But now the problem is that I can't call one of the function.... Mar 16, 2018 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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