2

I have two contracts, they are connected via an interface.

When user calls contract1 function, it uses an interface to call contract2 function which updates it's storage.

My problem is that I can get a return value from an event, but data is not saved in that contract2 storage.

I get such an error:

Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!

here is a contract1 function which that user calls i.e. buy():

event itemBought(uint256 itemId);

Contract2Interface private contract2Interface;

constructor() public {
    contract2Interface = Contract2Interface('contract address');
}

function buy(uint256 itemId) public payable {
      // require(some condition);

    uint256 itemId = contract2Interface.buy(itemId, msg.sender);
    emit itemBought(itemId);
}

here is an interface:

contract contract2Interface {
    function buy(uint256 itemId, address owner) public returns(uint256);
}

here is contract2 function:

mapping(bytes32 => uint256) private storage;

function encodeFunc(uint256 itemId, address owner) private pure returns(bytes32) {
    return keccak256(abi.encodePacked(itemId, owner));
}

function buy(uint256 itemId, address owner) public returns(uint256) {
    storage[encodeFunc(itemId, owner)]++;
    return itemId;
}

So here I get that itemId from event, but data is not saved in storage, I don't get any errors either.

what do you think a problem is ?

Thank you!

0

Your contract seems fine. I think you should choose a different name for mapping here:

mapping(bytes32 => uint256) private storage;

As storage is a keyword in Solidity. Also try running your contracts in REMIX, it can save you from these kind of mistakes.

  • Thank you for your reply! But I just renamed that variable from my long camel case one to just that simple 'storage'. Sorry for my misleading you. regarding Remix: I compiled and deployed my contracts using it. and today I could catch such an error: > Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined! – Costa Rassco Dec 27 '18 at 14:53
  • I have tried increasing my gas limit and now it works pretty fine, but data is not saved anyway. If I call contract2 function which updates it's state then I should see those transactions, right ? – Costa Rassco Dec 27 '18 at 15:25
  • still couldn't resolve that issue, is there any problem there except that variable name ? – Costa Rassco Dec 28 '18 at 21:06

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.