Code Monkey home page Code Monkey logo

ethereum-ruby's Introduction

Ethereum library for Ruby

A simple library for Ethereum.

Features

  • Pure Ruby implementation
  • IPC Client with batch calls support
  • HTTP Client with batch calls support
  • Compile and deploy Solidity contracts
  • Deploy contracts with constructor parameters.
  • Expose deployed contracts as Ruby classes
  • Test solidity contracts with a Ruby testing framework of your choice
  • Call and wait for the result of Solidity function calls.
  • Contract events

Ruby Compatibility

  • Ruby 2.x
  • Ruby 1.9.x
  • JRuby
  • Rubinius

Requirements

We currently support UNIX/Linux environments and Windows IPC support on the roadmap.

You will need to have a properly working Ruby installation. We recommend RVM

To use this library you will need to have a running Ethereum node with IPC support enabled (default). We currently support Go-Ethereum client

Installation

Add this line to your application's Gemfile:

gem 'ethereum'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ethereum

Basic Usage

IPC Client Connection

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

Solidity contract compilation and deployment

init = Ethereum::Initializer.new("#{ENV['PWD']}/spec/fixtures/SimpleNameRegistry.sol", client)
init.build_all
simple_name_registry_instance = SimpleNameRegistry.new
simple_name_registry_instance.deploy_and_wait(60)

Transacting and Calling Solidity Functions

Solidity functions are exposed using the following conventions:

transact_[function_name](params) 
transact_and_wait_[function_name](params)  
call_[function_name](params)

Example Contract in Solidity

contract SimpleNameRegistry {

  mapping (address => bool) public myMapping;

  function register(address _a, bytes32 _b) {
  }

  function getSomeValue(address _x) public constant returns(bool b, address b) {
  }

}
simple_name_registry_instance.transact_and_wait_register("0x5b6cb65d40b0e27fab87a2180abcab22174a2d45", "minter.contract.dgx")
simple_name_registry_instance.transact_register("0x385acafdb80b71ae001f1dbd0d65e62ec2fff055", "[email protected]")
simple_name_registry_instance.call_get_some_value("0x385acafdb80b71ae001f1dbd0d65e62ec2fff055")
simple_name_registry_instance.call_my_mapping("0x385acafdb80b71ae001f1dbd0d65e62ec2fff055")

Run contracts using a different address

simple_name_registry_instance.as("0x0c0d99d3608a2d1d38bb1b28025e970d3910b1e1")

Point contract instance to a previously deployed contract

simple_name_registry_instance.at("0x734533083b5fc0cd14b7cb8c8eb6ed0c9bd184d3")

Roadmap

  • Add Windows IPC Client (named pipes)
  • Add support for creating and sending of raw transactions
  • Offline account creation
  • ContractTransaction class
  • Add more examples
  • API documentation
  • Unit testing and contract testing examples. Use web3.js tests as a baseline.

Support

Please join our Gitter chat room or open a new issue in this repository

Gitter

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/DigixGlobal/ethereum-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

ethereum-ruby's People

Contributors

alexhanh avatar tymat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethereum-ruby's Issues

Unanable to run solc compliers

I am new to ethereum implementation

when i try to DO Solidity contract compilation and deployment process, I am getting the following error.Please do needful to fix this problem.

SystemCallError: unknown error - Unanable to run solc compliers
from /home/haloprabu/.rvm/gems/ruby-2.4.0@blockchain/gems/ethereum.rb-2.0.8/lib/ethereum/solidity.rb:35:in `execute_solc'

Please do let me know what might be wroung.

Various Version with rubygem and github

Hi,
I notice that the version on rubygem is 0.5.2 while the this repo holds 1.5.2.
Is there any reason that not to push it to rubygems.org? Or do you have any recommend that which version is more stable?

Thanks

New IpcClient from docker container

My IpcClient is running on a docker container. So how am I going to point it's geth.ipc when I initialize this line??

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

can i connect geth remotely

hi, all. Thx for contributors nice work. ๐Ÿบ
my geth service is deployed server A, and I want to connect it remotely.
and i found allow connect client by ipc locally only

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

Is there a way connect geth remotely? thx

How to store JSON information on blockchain?

Hey,

I know this is not the right place to post this, But i'm left with no option since I've tried stack overflow and multiple sources for help and none really did.

Can anyone guide me through storing and retrieving a simple JSON string using the blockchain?

Help is much appreciated.

int, int64, etc do not work

Great library!

But if I have a method that takes in a SIGNED integer of some kind, when I call that method, I get an error. I have verified these methods work fine in geth.

Here is the error:

NameError: undefined local variable or method `uint' for #Ethereum::Formatter:0x007fb913c7fc58

Not sure why that's the error message but I narrowed it down to only happening when I refer to signed int's in the call interface for a method.

Events

I would love to use the events handling in this library. But how? There is no documentation on this. I see that every event in a smart contract has a gfc_event_name, gfl_event_name, and nf_event_name call, but no idea how to use any of these.

Please advise.

JSON::ParserError: 776

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"}}

Can't perform any Action

Hi,

 While I perform any action, getting below error. Please help me.

757: unexpected token at '{"jsonrpc":"2.0","error":{"code":-32600,"message":"EOF"}}

Thanks,
Santosh

eth_compileSolidity does not exist

Seems like client.compile_solidity is not working. Do you have any work around for this??

client.compile_solidity("SimpleNameRegistry.sol")
=> {"jsonrpc"=>"2.0", "id"=>5, "error"=>{"code"=>-32601, "message"=>"The method 
eth_compileSolidity does not exist/is not available"}} 

undefined method `eventName' for #<Ethereum::Contract:0x007fa63617ab40>

hi, thx for contributors nice and hard work. I met a problem and look for help here.
I have build and deploy a smart contract, get the contract object in irb as follow

2.3.1 :067 > con = Ethereum::Contract.new("hello",contracts[0].code, contracts[0].abi)
=> #<Ethereum::Contract:0x007fa63617ab40 @name="hello", @code="0x6060604052600080546c0100000000000000000000000033810204600160a060020a031990911617905560ed806100366000396000f36060604052361560275760e060020a600035046341c0e1b581146075578063e522538114609f575b60eb6000341115607357604080513481529051605891600160a060020a033316917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a159181900360200190a35b565b3460025760eb60005433600160a060020a0390811691161415607357600054600160a060020a0316ff5b3460025760eb60005433600160a060020a039081169116141560735760008054604051600160a060020a0391821692309092163180156108fc0292909190818181858888f15050505050565b00", @abi=[{"constant"=>false, "inputs"=>[], "name"=>"kill", "outputs"=>[], "payable"=>false, "type"=>"function"}, {"constant"=>false, "inputs"=>[], "name"=>"collect", "outputs"=>[], "payable"=>false, "type"=>"function"}, {"inputs"=>[], "type"=>"constructor"}, {"payable"=>true, "type"=>"fallback"}, {"anonymous"=>false, "inputs"=>[{"indexed"=>true, "name"=>"_from", "type"=>"address"}, {"indexed"=>true, "name"=>"_band", "type"=>"uint256"}, {"indexed"=>false, "name"=>"_value", "type"=>"uint256"}], "name"=>"Deposit", "type"=>"event"}], @functions=[#<Ethereum::Function:0x007fa63617a5a0 @name="kill", @constant=false, @inputs=[], @outputs=[], @function_string="kill()", @Signature="41c0e1b5">, #<Ethereum::Function:0x007fa63680ea10 @name="collect", @constant=false, @inputs=[], @outputs=[], @function_string="collect()", @Signature="e5225381">], @events=[#<Ethereum::ContractEvent:0x007fa6364219c0 @name="Deposit", @input_types=["address", "uint256", "uint256"], @inputs=["_from", "_band", "_value"], @event_string="Deposit(address,uint256,uint256)", @Signature="90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15">], @constructor_inputs=[]>

there is event named Deposit in the contract, and i want to do as web3.js method in Ruby

var event = myContractInstance.MyEvent({valueA: 23} [, additionalFilterObject])
event.watch(function(error, result){
  if (!error)
    console.log(result);
});

But when coninstance call Deposit method, NoMethodError: undefined method `Deposit' for #<Ethereum::Contract:0x007fa63617ab40> error occur
meanwhile, when i call watch method by event object

2.3.1 :074 > instance = SmartExchange.new
 => #<SmartExchange:0x007fa63631b6e8>

the same error occur. ๐Ÿ˜ฆ
Is there a way to call event.watch method as web3.js contract-events
many thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.