29

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."

3 Answers 3

40

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.

3
  • 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
    Commented Jan 29, 2018 at 22:23
  • 1
    @AndiGiga - I hope this doesn't sound like a dopey querstion, but: did you mean to say "2204 * 68 + 21000"?
    – jimkberry
    Commented Feb 6, 2018 at 21:40
  • Thx, that's the point I was too blind to see the 8.
    – Andi Giga
    Commented Feb 6, 2018 at 21:58
6

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 {
2
  • why this is not the answer for the question? it save my life just add one key word.
    – temple
    Commented Mar 13, 2017 at 21:21
  • 2
    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. Commented Mar 13, 2018 at 7:50

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