web3ethereum 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 309f2f779354771cca7c0b4862f8c0a82e9bdc07b7e2a2d7bc165cbea3fdd9ea
4
+ data.tar.gz: b9bf7511979e486a6dcb2e3175326c8f3bbf7ca937534f88a205024ce4b0229d
5
+ SHA512:
6
+ metadata.gz: ea3339137b95ca627b956f4dc69aa177495e05c9d7189c22ec7c15250dc84839025240ae98a12be6eb9823c1657296da82c6beb8ee79ea66973b9fa765526476
7
+ data.tar.gz: 0d2fb412b049e9a7ac28bbf57526426acb5f8947db952e6cacb69fe6d6fdc6d4a516bd9d1556f50a93fd5161794052af125665c4540a722fb37fad602dc0125b
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # [1.0.0]
2
+
3
+ ## [1.0.0] - 2021-04-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@willbinns.org. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in web3eth.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # web3ethereum
2
+
3
+ Connect with a local or remote node to interact with the Ethereum network and
4
+ call RPC methods in your Ruby or Rails apps.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'web3ethereum'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install web3ethereum
21
+
22
+ ## Usage
23
+
24
+ ### Connect
25
+
26
+ Connecting to local node ( or by SSH Tunnel )
27
+
28
+ ```ruby
29
+ web3 = Web3::Eth::Rpc.new
30
+ ```
31
+
32
+ To connect to remote Ethereum node, follow instructions: https://github.com/paritytech/parity/wiki/Wallet-Remote-Access
33
+
34
+ If you need to connect to remote host, you can specify host, port and HTTP connection options:
35
+
36
+ ```ruby
37
+ web3 = Web3::Eth::Rpc.new host: 'node.host.com',
38
+ port: 8545,
39
+ connect_options: { use_ssl: true, read_timeout: 120 }
40
+ ```
41
+
42
+ HTTP connection options are from [Ruby HTTP](https://ruby-doc.org/stdlib-2.4.2/libdoc/net/http/rdoc/Net/HTTP.html) plus additional optional property
43
+ **rpc_path** - path to RPC interface.
44
+
45
+ For example, to connect to Infura node, you need the following configuration:
46
+
47
+ ```ruby
48
+ web3 = Web3::Eth::Rpc.new host: 'mainnet.infura.io',
49
+ port: 443,
50
+ connect_options: {
51
+ open_timeout: 20,
52
+ read_timeout: 140,
53
+ use_ssl: true,
54
+ rpc_path: '/v3/<YOUR INFURA PERSONAL KEY>'
55
+ }
56
+ ```
57
+
58
+ or to connect to Ropsten:
59
+
60
+
61
+ ```ruby
62
+ web3 = Web3::Eth::Rpc.new host: 'ropsten.infura.io',
63
+ port: 443,
64
+ connect_options: {
65
+ open_timeout: 20,
66
+ read_timeout: 140,
67
+ use_ssl: true
68
+ }
69
+ ```
70
+
71
+ ### Calling eth interface
72
+
73
+ ```
74
+ >> web3.eth.blockNumber
75
+ 4376369
76
+
77
+ >> web3.eth.getBalance '0x829BD824B016326A401d083B33D092293333A830'
78
+ 3916.6597314456685
79
+
80
+ >> block = web3.eth.getBlockByNumber 4376369
81
+ #<Web3::Eth::Block:0x007f844d6f1138 @block_data={"author"=>"0x829bd824b016326a401d083b33d092293333a830", ...
82
+
83
+ >> block.timestamp_time
84
+ 2017-10-17 12:51:36 +0300
85
+
86
+ >> block.transactions.count
87
+ 129
88
+
89
+ >> block.transactions[0].from
90
+ "0xb2930b35844a230f00e51431acae96fe543a0347"
91
+
92
+ >> block.transactions[0].value_eth
93
+ 0.51896811
94
+
95
+ ```
96
+
97
+ ### Calling Etherscan API:
98
+
99
+ ```
100
+ api = Web3::Eth::Etherscan.new 'Your API Key'
101
+ abi = api.contract_getabi address: '0xe3fedaecd47aa8eab6b23227b0ee56f092c967a9'
102
+ ```
103
+
104
+ Method name for Etherscan must be constructed as <module>_<action>, for example contract_getabi
105
+ calls method getabi in module contract
106
+
107
+ If method accepts only one parameter address, the call can be simplified to:
108
+
109
+ ```
110
+ abi = api.contract_getabi '0xe3fedaecd47aa8eab6b23227b0ee56f092c967a9'
111
+ ```
112
+
113
+ ### Accesing contract methods
114
+
115
+ ```
116
+ # creation of contract object
117
+ myContract = web3.eth.contract(abi);
118
+
119
+ # initiate contract for an address
120
+ myContractInstance = myContract.at('0x2ad180cbaffbc97237f572148fc1b283b68d8861');
121
+
122
+ # call constant function
123
+ result = myContractInstance.balanceOf('0x...'); # any constant method works
124
+ puts result
125
+ ```
126
+
127
+ or using Etherscan API ( requires contract ABI be published in Etherescan ):
128
+
129
+ ```
130
+ api = Web3::Eth::Etherscan.new 'Your API Key'
131
+ myContractInstance = web3.eth.load_contract(api, '0x2ad180cbaffbc97237f572148fc1b283b68d8861')
132
+
133
+ // call constant function
134
+ result = myContractInstance.balanceOf('0x....'); # any constant method works
135
+ puts result // '0x25434534534'
136
+ ```
137
+
138
+
139
+ ### Parsing transaction call arguments
140
+
141
+ Method parse_call_args parses call arguments according to ABI.
142
+ Code example is:
143
+
144
+ ```
145
+ api = Web3::Eth::Etherscan.new 'Your API Key'
146
+ abi = api.contract_getabi address: '0x2ad180cbaffbc97237f572148fc1b283b68d8861'
147
+
148
+ myContract = web3.eth.contract(abi);
149
+ tx = web3.eth.getTransactionByHash '0x83da408b05061a2512fe1abf065b37a6aad9ae96d604b288a3da34bf9f1af9e6'
150
+ myContract.parse_call_args tx
151
+ ```
152
+
153
+ ### Parsing smart contract constructor arguments
154
+
155
+ Method parse_constructor_args parses smart contract creation arguments according to ABI.
156
+ Code example is:
157
+
158
+ ```
159
+ api = Web3::Eth::Etherscan.new 'Your API Key'
160
+ abi = api.contract_getabi address: '0xf4702b0918a8a89dfc38459ce42198834818f26b'
161
+
162
+ myContract = web3.eth.contract(abi);
163
+ tx = web3.eth.getTransactionByHash '0x35f0cf1d1c7ec14dd40fe3949d1c535ec3f3953f118cb9dc1394370f966cf957'
164
+ myContract.parse_constructor_args tx
165
+ ```
166
+
167
+ ### Parsing transaction logs
168
+
169
+ Method parse_log_args parses indexed and not-indexed log event arguments according to ABI.
170
+ Code example is:
171
+
172
+ ```
173
+ api = Web3::Eth::Etherscan.new 'Your API Key'
174
+ abi = api.contract_getabi address: '0x2ad180cbaffbc97237f572148fc1b283b68d8861'
175
+
176
+ myContract = web3.eth.contract(abi);
177
+ tx_receipt = web3.eth.getTransactionReceipt '0x83da408b05061a2512fe1abf065b37a6aad9ae96d604b288a3da34bf9f1af9e6'
178
+ myContract.parse_log_args tx_receipt.logs.first
179
+ ```
180
+
181
+ ### Listing internal transactions
182
+
183
+ To use this feature, you should run parity node with the option
184
+ --tracing on, refer to [https://github.com/paritytech/parity/wiki/Configuring-Parity#cli-options].
185
+
186
+ ```
187
+ calls = web3.trace.internalCallsByHash '0x7ac18a1640e443cd069ff51da382b92b585e42dae8f38db0932380bfe86908a6'
188
+ puts calls.first.from
189
+ puts calls.first.to
190
+ puts calls.first.value_eth
191
+ ```
192
+
193
+ ## Development
194
+
195
+ 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.
196
+
197
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
198
+
199
+ ## Contributing
200
+
201
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wbnns/web3eth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/wbnns/web3eth/blob/master/CODE_OF_CONDUCT.md).
202
+
203
+ ## License
204
+
205
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
206
+
207
+ ## Code of Conduct
208
+
209
+ Everyone interacting in the Web3eth project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wbnns/web3eth/blob/master/CODE_OF_CONDUCT.md).
210
+
211
+ ## Acknowledgements
212
+
213
+ This gem would not be possible without the work of **Izetex**. It is entirely
214
+ based on code from his [web3-eth library](https://github.com/izetex/web3-eth),
215
+ which appears to no longer be maintained.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "web3eth"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here