4

Contract code:

function rand( uint256 seedB ) returns (uint256){ 

    //define seedA variable
    uint256 seedA = 1;

    uint amount = 1 finney;

    if (seedA == seedB) { 
        msg.sender.send(amount);
    }


    return seedA + seedB; 
}

https://gist.github.com/anonymous/e210a052b6b4c86337c2

Basically, if SeedA (which equals 1) equals SeedB it sends amount to msg.sender.


Why does this not work, when I am calling the function using:

random.rand.sendTransaction(1,
    {from: eth.accounts[0], 
    value: web3.toWei(.0001, 'ether'), 
    to: '0x4abc14efad9a7a84a0a9ef6e1a782c43a9e3f550', 
    gas: 500000,  data: web3.fromAscii('message')})

Here is the contract address: https://www.etherchain.org/account/0x4abc14efad9a7a84a0a9ef6e1a782c43a9e3f550

Am I invoking the contract improperly in the sendTransaction? I am invoking it from inside my local geth client.

How do I ensure my parameter (1) is passed into the contract function rand via sendTransaction?

6

In your contract you are trying to send 1 finney, but you are only providing your contract with 0.1 finney... A Finney is 0.001 ETH, not 0.0001

  • OMG. My code has been working all day. You do not want to know how long I have been trying to work this out. I have stripped back my code to bare basics because of this error LOOOOL THANK YOU. It now works, you can see the first sent tx from the contract address: etherchain.org/account/… – user2890278 Feb 5 '16 at 14:28
  • 1
    No problem. You can also use "finney" as the units in web3.fromWei – Tjaden Hess Feb 5 '16 at 14:30
  • 2
    Also, you don't need to put the to: field in the tx object. It gets filled in automatically – Tjaden Hess Feb 5 '16 at 14:32
2

It might be because you supply data when calling sendTransaction on an actual function, overriding the function identifier and the function argument you gave (1).

2

Try web3.eth.defaultAccount = web3.eth.accounts[0]

and then random.rand.sendTransaction(1)

  • 1
    The transactions are going through, just I am not seeing that seedA == seedB because if it did it would send me 1 Finney. – user2890278 Feb 5 '16 at 14:08

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.