5

I'd like to connect geth by IPC on rails. I start geth as follows.

$build/bin/geth --datadir "/home/vagrant/.ethereum" --networkid "1" --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --ipcpath "/home/vagrant/.ethereum/geth.ipc"

Then I tried to connect from rails console using ethereum-ruby. However, it returns error. Could you tell me how to connect geth from ruby?(It doesn't matter whether it is used the library or not.

[1] pry(main)> client = Ethereum::IpcClient.new("#{ENV['HOME']}/.ethereum/geth.ipc")
=> #<Ethereum::IpcClient:0x007f4f4365f470
 @batch=[],
 @id=1,
 @ipcpath="/home/vagrant/.ethereum/geth.ipc">
[2] pry(main)> client.eth_coinbase
NoMethodError: undefined method `eth_coinbase' for #<Ethereum::IpcClient:0x007f4f4365f470>
from (pry):2:in `<main>'
  • I can reproduce this, it's either a bug or a lack of documentation. – Waqar Lim Feb 24 '16 at 7:52
3

You are using the wrong command, the command is coinbase, not eth_coinbase.

I suggest to use this code:

eth = Ethereum::IpcClient.new 

This will automatically use the default path to get geth.ipc

puts eth.coinbase["result"]

And this will return your coinbase.

You can see that this line, used to create the new method, is not getting the first part of the rpc method name, and, it's underscoring the method, so eth_coinbase will be coinbase, eth_getBalance will be get_balance and so on.

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.