The Coin Tutorial: How can I know that the `sendCoin` has the attribute `sendTransaction`?

starstarstarstar Member Posts: 19
The contract definition of the sendCoin function is:
 /* Very simple trade function */
    function sendCoin(address receiver, uint amount) returns(bool sufficient) {
        if (coinBalanceOf[msg.sender] < amount) return false;
        coinBalanceOf[msg.sender] -= amount;
        coinBalanceOf[receiver] += amount;
        CoinTransfer(msg.sender, receiver, amount);
        return true;
But then, on the `geth` command line, it is invoked as:

token.sendCoin.sendTransaction(eth.accounts[1], 1000, {from: eth.accounts[0]})

First, I didn't define the `sendTransaction` function (I guess that's somehow implied in the contract deployment) and second, the signature is different. I only define a receiver addres and an ammount, but here I'm providing, in addition, a `{from: eth.accounts[0]}` block (whatever the hell that is). If I didn't know this, I would thus not be able to call my own contract. Where can I find the attributes, added after deployment, of my contract functions?


  • o0ragman0oo0ragman0o Member, Moderator Posts: 1,291 mod
    @starstar The geth command line is using the web3.js API
    What you're seeing in the {} is the transaction object which can be set after all other explicit parameters and determines among other things who pays the gas, how much to send, etc. There is also provision to set callback functions in a sendTransaction which get called once the block is mined.

    sendTransaction is a native member of address but in this instance there looks to be a convention to invoke it on the contracts functions also. You should be able to call token.sendCoin(eth.account[1], 1000, {from: eth.accounts[0]}) with the same effect.
  • starstarstarstar Member Posts: 19
    Thanks, really helpful.
Sign In or Register to comment.