I am working on a private test net. I have deployed a contract using Ethereum wallet. And in the contract I have a function to transfer coins from one account to other.

function transfer(address _to, uint256 _value) {
    if (balanceOf[msg.sender] < _value) throw;           // Check if the sender has enough
    if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
    balanceOf[msg.sender] -= _value;                     // Subtract from the sender
    balanceOf[_to] += _value;                            // Add the same to the recipient
    Transfer(msg.sender, _to, _value);                   // Notify anyone listening that this transfer took place

I am able to transfer coins using Ethereum wallet but didn't know how to do the same using geth console.

Then I came accross eth.contract(ABI).at(Address);

which was a solution to my problem. But while using:

var cont=eth.contract(ABI).at(Address);
cont.transfer("0x506B2FAcCC8fF7f1F9633491985E0b997c6F5Fc7", 100)

I am getting errors:

invalid address
at web3.js:3887:15
at web3.js:3713:20
at web3.js:4939:28
at web3.js:4938:12
at web3.js:4964:18
at web3.js:4989:23
at web3.js:4055:16
at web3.js:4141:16
at <anonymous>:1:1.

I am beginner to Ethereum. Don't know even if I am going right?

  • Please post the contract code and update the question with the following: - do you plan on making your own currency? If so there is a great step by step tutorial here. - is the other account aware of the new type of currency (see the linked tutorial)? - what do you mean by CC1?
    – Sebi
    Jul 21 '16 at 14:35

What you need to do is to add the {from: account} account details that the transaction is to be sent from:

var cont=eth.contract(ABI).at(Address);
cont.transfer("0x506B2FAcCC8fF7f1F9633491985E0b997c6F5Fc7", 100, {from: account})
  • Thanks. It worked well. But can you please expalin why I need to do that. Jul 23 '16 at 12:55
  • Sending the contract to the blockchain requires you to pay some fees for the gas. An account needs to be specified for the fees to be paid from, and this is how the account is specified in the transaction statement. You can see the same type of statement in ethereum.stackexchange.com/a/2789/1268 - var greeter = greeterContract.new(_greeting,{from: eth.accounts[0], data: greeterCompiled.greeter.code, gas: 4000000}, .... Jul 23 '16 at 13: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.