Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON::ParserError: 776 #7

Open
lgs opened this issue Jul 3, 2016 · 5 comments
Open

JSON::ParserError: 776 #7

lgs opened this issue Jul 3, 2016 · 5 comments

Comments

@lgs
Copy link

lgs commented Jul 3, 2016

Binding Ethereum node into a Rails app, get 'JSON::ParserError: 776'.
I have a node running APIs via IPC like:

geth --ipcapi "admin,eth,debug,miner,net,shh,txpool,personal,web3"

and in Rails console I can do

client = Ethereum::IpcClient.new("#{ENV['HOME']}/.ethereum/geth.ipc")

but when I try puts client.coinbase["result"] I get and error:

JSON::ParserError: 776: unexpected token at '{"jsonrpc":"2.0","error":{"code":-32600,"message":"EOF"}}
@lgs
Copy link
Author

lgs commented Jul 4, 2016

oh my gosh ...

lsoave@basenode:~/github/ethereum-ruby$ bundle exec rspec
Ethereum
  HttpClient
    should work
  IpcClient
    should work (FAILED - 1)
    should support batching (FAILED - 2)
Ethereum
  Ethereum Version
    has a version number (FAILED - 3)
  Deployment
    should deploy a contract with parameters (FAILED - 4)
  Basic contract testing
    should perform a contract transaction, wait for its completion, return an Ethereum::Transaction object (FAILED - 5)
    should test a call_(Ethereum Contract Function) (FAILED - 6)
Failures:
  1) Ethereum IpcClient should work
     Failure/Error: socket = UNIXSocket.new(@ipcpath)
     
     Errno::ENOENT:
       No such file or directory - connect(2) for /home/lsoave/EtherDev/data/geth.ipc
     # ./lib/ethereum/ipc_client.rb:12:in `initialize'
     # ./lib/ethereum/ipc_client.rb:12:in `new'
     # ./lib/ethereum/ipc_client.rb:12:in `send_single'
     # ./lib/ethereum/client.rb:57:in `block (2 levels) in '
     # ./spec/client_spec.rb:17:in `block (3 levels) in '
  2) Ethereum IpcClient should support batching
     Failure/Error: socket = UNIXSocket.new(@ipcpath)
     
     Errno::ENOENT:
       No such file or directory - connect(2) for /home/lsoave/EtherDev/data/geth.ipc
     # ./lib/ethereum/ipc_client.rb:12:in `initialize'
     # ./lib/ethereum/ipc_client.rb:12:in `new'
     # ./lib/ethereum/ipc_client.rb:12:in `send_single'
     # ./lib/ethereum/ipc_client.rb:27:in `send_batch'
     # ./lib/ethereum/client.rb:24:in `batch'
     # ./spec/client_spec.rb:21:in `block (3 levels) in '
  3) Ethereum Ethereum Version has a version number
     Failure/Error: expect(Ethereum::VERSION).to eq("0.4.90")
     
       expected: "0.4.90"
            got: "1.5.2"
     
       (compared using ==)
     # ./spec/ethereum_spec.rb:12:in `block (3 levels) in '
  4) Ethereum Deployment should deploy a contract with parameters
     Failure/Error: sol_output = @client.compile_solidity(@file)
     
     NoMethodError:
       undefined method `compile_solidity' for #
     # ./lib/ethereum/initializer.rb:9:in `initialize'
     # ./spec/ethereum_spec.rb:18:in `new'
     # ./spec/ethereum_spec.rb:18:in `block (3 levels) in '
  5) Ethereum Basic contract testing should perform a contract transaction, wait for its completion, return an Ethereum::Transaction object
     Failure/Error: sol_output = @client.compile_solidity(@file)
     
     NoMethodError:
       undefined method `compile_solidity' for #
     # ./lib/ethereum/initializer.rb:9:in `initialize'
     # ./spec/ethereum_spec.rb:33:in `new'
     # ./spec/ethereum_spec.rb:33:in `block (3 levels) in '
  6) Ethereum Basic contract testing should test a call_(Ethereum Contract Function)
     Failure/Error: sol_output = @client.compile_solidity(@file)
     
     NoMethodError:
       undefined method `compile_solidity' for #
     # ./lib/ethereum/initializer.rb:9:in `initialize'
     # ./spec/ethereum_spec.rb:33:in `new'
     # ./spec/ethereum_spec.rb:33:in `block (3 levels) in '
Finished in 0.01874 seconds (files took 0.38199 seconds to load)
7 examples, 6 failures
Failed examples:
rspec ./spec/client_spec.rb:16 # Ethereum IpcClient should work
rspec ./spec/client_spec.rb:20 # Ethereum IpcClient should support batching
rspec ./spec/ethereum_spec.rb:11 # Ethereum Ethereum Version has a version number
rspec ./spec/ethereum_spec.rb:17 # Ethereum Deployment should deploy a contract with parameters
rspec ./spec/ethereum_spec.rb:39 # Ethereum Basic contract testing should perform a contract transaction, wait for its completion, return an Ethereum::Transaction object
rspec ./spec/ethereum_spec.rb:44 # Ethereum Basic contract testing should test a call_(Ethereum Contract Function)

@alexhanh
Copy link
Contributor

alexhanh commented Jul 5, 2016

@lgs what version of geth are you running? I got it working with my fork https://github.com/alexhanh/ethereum-ruby
$ geth version Geth Version: 1.4.9-stable-b7e3dfc5
geth --datadir ~/EtherDev/data --minerthreads 1 --nodiscover --maxpeers 0 console
IPC endpoint opened: /Users/alexhanh/EtherDev/data/geth.ipc

Then

client = Ethereum::IpcClient.new("/Users/alexhanh/EtherDev/data/geth.ipc")
puts client.eth_gas_price
{"jsonrpc"=>"2.0", "id"=>1, "result"=>"0x4a817c800"}

@alexhanh
Copy link
Contributor

alexhanh commented Jul 9, 2016

I decided to release a simple JSON RPC client gem https://github.com/alexhanh/jeth. Perhaps ethereum-ruby could use that.

@lgs
Copy link
Author

lgs commented Jul 9, 2016

@alexhanh that's good idea but just use #new instead of #create:

$ rails c
Running via Spring preloader in process 5827
Loading development environment (Rails 5.0.0)
irb(main):001:0> client = Jeth::IpcClient.create
NoMethodError: undefined method `create' for Jeth::IpcClient:Class
    from (irb):1
...
irb(main):002:0> client = Jeth::HttpClient.create('http://localhost:8545')
NoMethodError: undefined method `create' for Jeth::HttpClient:Class
    from (irb):4
irb(main):057:0>  client = Jeth::HttpClient.new('http://localhost:8545')
=> # < Jeth::HttpClient:0x005621b980e6f8 @id=0,  @batch=nil, @host="localhost", 
     @port=8545, @ssl=false, @uri=# >
irb(main):058:0> client.eth_gas_price
=> {"jsonrpc"=>"2.0", "id"=>1, "result"=>"0x4a817c800"}
irb(main):059:0> client = Jeth::IpcClient.create
NoMethodError: undefined method `create' for Jeth::IpcClient:Class
    from (irb):59
irb(main):060:0> client = Jeth::IpcClient.new
=> #
irb(main):061:0> client.eth_gas_price
=> {"jsonrpc"=>"2.0", "id"=>1, "result"=>"0x4a817c800"}

the only one working like the README is client = Jeth.create

irb(main):062:0> client = Jeth.create
=> #
irb(main):063:0> client.eth_gas_price
=> {"jsonrpc"=>"2.0", "id"=>1, "result"=>"0x4a817c800"}

@alexhanh
Copy link
Contributor

alexhanh commented Jul 9, 2016

@tymat This pull request fixes the issues #8, feel free to close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants