6

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>'
1
  • I can reproduce this, it's either a bug or a lack of documentation.
    – q9f
    Feb 24, 2016 at 7:52

2 Answers 2

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.

0

If you use the new eth gem, you would have to create an IPC client:

ipc = Eth::Client.create "/home/vagrant/.ethereum/geth.ipc"
ipc.eth_coinbase # or: ipc.default_account

See: https://github.com/q9f/eth.rb/wiki/RPC-Client

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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