21

I'm running the Mist wallet, and I've deployed this contract to testnet (from https://ethereum.stackexchange.com/a/179/520) :

contract Notary{
    struct Document {
        uint timestamp;
        bytes ipfs_hash;
        address[] signatures;
    }
    mapping(address => bytes[]) public users; //maps addresses to ipfs document hashes
    mapping(bytes32 => Document) public documents; //maps sha3(ipfs) hashes to documents

    function addDocument(bytes ipfs) public {
        users[msg.sender].push(ipfs); //Add document to users's "signed" list
        address[] memory sender;
        sender[0] = msg.sender;
        documents[sha3(ipfs)] = Document(block.timestamp, ipfs, sender);
    }

    function signDocument(bytes ipfs) public {
        users[msg.sender].push(ipfs);
        documents[sha3(ipfs)].signatures.push(msg.sender);
    }

}

When I try to execute the addDocument function though, I get "intrinsic gas too low". What does this mean? Also before confirming execution, it says: "Data can't be executed, so it will use all provided gas."

20

The intrinsic gas for a transaction is the amount of gas that the transaction uses before any code runs. It is a constant “transaction fee” (currently 21000 gas) plus a fee for every byte of data supplied with the transaction (4 gas for a zero byte, 68 gas for non-zeros). These constants are all currently defined for geth in params/protocol_params.go. Presumably they are also coded into the source for the other node/client implementations as well.

  • I'm trying to send a tx with Metamask on Ropsten with 2204 bytes so I used: 2204 * 64 + 21000 gas but I still get Intrinsic gas too low. Shouldn't it even require less gas because of the zero bytes? – Andi Giga Jan 29 '18 at 22:23
  • @AndiGiga - I hope this doesn't sound like a dopey querstion, but: did you mean to say "2204 * 68 + 21000"? – jimkberry Feb 6 '18 at 21:40
  • Thx, that's the point I was too blind to see the 8. – Andi Giga Feb 6 '18 at 21:58
5

You need to allocate more gas to your transaction with the addDocument function. Mist is looking ahead and is able to tell that the transaction will fail because you haven't given the transaction enough gas to execute with.

4

The keyword payable is needed on a function. See solidity docs:

Payable for functions: Allows them to receive Ether together with a call.

So, this doesn't work:

function transfer(address _to, uint256 _value) {

This does work:

function transfer(address _to, uint256 _value) payable {
  • why this is not the answer for the question? it save my life just add one key word. – temple Mar 13 '17 at 21:21
  • 1
    I am downvoting this answer, because this is factually incorrect. payable keyword is only needed when the function receives ETH. The incorrect use of payable keyword may cause the users to lose their ether. – Mikko Ohtamaa Mar 13 '18 at 7:50

protected by eth Dec 7 '17 at 18:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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