izetex / web3-eth Goto Github PK
View Code? Open in Web Editor NEWWeb3 Ruby gem client for Ethereum
License: MIT License
Web3 Ruby gem client for Ethereum
License: MIT License
Hello,
there is a problem when i try to use web3.contract(abi)
here is my code:
`abi = {"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burn","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_value","type":"uint256"}],"name":"burnFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialSupply","type":"uint256"},{"name":"tokenName","type":"string"},{"name":"decimalUnits","type":"uint8"},{"name":"tokenSymbol","type":"string"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"}
myContract = web3.eth.contract(abi)`
here is the exception:
NoMethodError: undefined method
compact' for #Hash:0x000000014fdbb0
from /var/lib/gems/2.3.0/gems/web3-eth-0.1.0/lib/web3/eth/rpc.rb:42:in block in request' from /usr/lib/ruby/2.3.0/net/http.rb:853:in
start'
from /usr/lib/ruby/2.3.0/net/http.rb:584:in start' from /var/lib/gems/2.3.0/gems/web3-eth-0.1.0/lib/web3/eth/rpc.rb:39:in
request'
from /var/lib/gems/2.3.0/gems/web3-eth-0.1.0/lib/web3/eth/ethereum.rb:37:in method_missing' from (irb):27 from /usr/bin/irb:11:in
Thank you in advance
When I run this:
web3 = Web3::Eth::Rpc.new host: 'ropsten.infura.io/my_api_key',
port: 443,
connect_options: {
open_timeout: 20,
read_timeout: 140,
use_ssl: true
}
# render html: web3.eth.blockNumber
abi = [...myMethod...]
contract = web3.eth.contract(abi)
contractInstance = contract.at('...')
result = contractInstance.myMethod(...)
puts result
I get a RuntimeError (Function myMethod is not constant: myMethod, requires to sign transaction)
. How do you sign a method call transaction?
Is there a way to call a function (i.e. send a transaction) with this library?
If I wanted to programmatically call a function that updates blockchain state, what's the best way to do it?
I'm try get data to send erc20 token to address ether and my code here
web3 = Web3::Eth::Rpc.new host: 'ropsten.infura.io',
port: 443,
connect_options: {
open_timeout: 20,
read_timeout: 140,
use_ssl: true,
rpc_path: '/xxxxxxxxxx'
}
ERC_ABI = [{.....}]
contractAddr = "0xFf............"
contract = web3.eth.contract(ERC_ABI).at(contractAddr)
data = contract.transfer.getData('0xg.......', 10000, {from: '0xc........'})
then get error
RuntimeError: No method found in ABI: transfer
from (irb):24
pls help me, thanks all
Using the example code
api = Web3::Eth::Etherscan.new 'Your API Key'
abi = api.contract_getabi address: '0x2ad180cbaffbc97237f572148fc1b283b68d8861'
myContract = web3.eth.contract(abi);
tx = web3.eth.getTransactionByHash '0x83da408b05061a2512fe1abf065b37a6aad9ae96d604b288a3da34bf9f1af9e6'
myContract.parse_call_args tx
myContract.parse_call_args tx
call would produce the error
undefined local variable or method `creates' for #<Web3::Eth::Transaction:0x...>
I cannot use the Method Etherscan.new.
Traceback (most recent call last):
1: from (irb):1:in `
Please fix it.
When i am trying .parse_call_args
for transaction 0x37b0e2e0... all going well. But it doesn't work for transaction 0xe0a8cf7cd1c... which one provided by the same contract.
ABI: https://gist.github.com/IlyaDonskikh/dce68abcd26a4c06d2eb6e688b7bba1a (also trying to use: https://github.com/danfinlay/human-standard-token-abi/blob/master/index.js)
Error: RuntimeError: No function found by hash , probably ABI is not related to call
Gem: web3-eth (0.2.13)
Hi,everyone.
i have some issues.
web3.eth.getTransactionCount(account, 'pending') function not working.
Please help me.
best regards.
There are pull request not merged since 2018.
Hi @izetex @astudnev! ๐๐ป
First off, thank you so much for making this Ruby port of Web3. I was so happy to find a gem that works basically just like the Node/Python Web3 packages. It makes the prospect of doing ETH blockchain development way more appealing to me. ๐
As my first adventure into Web3 / Ethereum, I'm trying to port a small Node script that I inherited from an earlier person on the task.
This is the Node code that works.
// normal Web3 setup and connection
// โฆ
const contract = new web3.eth.Contract(abi, TOKEN_CONTRACT_ADDRESS);
const allEvents = yield contract.getPastEvents('Transfer', {
fromBlock: FROM_BLOCK,
toBlock: TO_BLOCK
});
Here's my current script.
require "json"
require "web3/eth"
FROM_BLOCK = 4899001
TO_BLOCK = 4900000
ETHEREUM_SERVER_HOST = "[SCRUBBED FOR DEMONSTRATION]"
ETHERSCAN_API_KEY_TOKEN = "[SCRUBBED FOR DEMONSTRATION]"
ABI_ADDRESS = "0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359"
TOKEN_CONTRACT_ADDRESS = "0x99ea4db9ee77acd40b119bd1dc4e33e1c070b80d"
web3 = Web3::Eth::Rpc.new host: ETHEREUM_SERVER_HOST,
port: 8545,
connect_options: { read_timeout: 120 }
api = Web3::Eth::Etherscan.new ETHERSCAN_API_KEY_TOKEN
abi = api.contract_getabi address: ABI_ADDRESS
contract = web3.eth.contract(abi);
# Everything up to here works
# =========================== #
# I thought that I found what I was looking for in #events,
# but it only returns 4 events. I was expecting thousands.
# Maybe I don't understand where to get what I'm looking for.
puts contract.events.count
# => 4
# =========================== #
# This doesn't work
# No method found in ABI: getPastEvents (RuntimeError)
puts contract.getPastEvents('Transfer', { fromBlock: FROM_BLOCK, toBlock: TO_BLOCK })
I must be missing something, right?
Thanks again for this gem. I look forward to using it lots more. ๐
web3-eth/lib/web3/eth/contract.rb
Line 87 in 11f02a0
Is there anyway for us to specify block number when calling to a contract?
Hi everyone.
I am going to send transaction with my private key using web3-eth gem.
But i can't find correct solution anywhere.
Please help me!
Best regards!
I am having some trouble trying to get a contract instance and call its methods from Rails. I am using truffle, web3-eth, and Rails 5.0+.
I deployed my contract to ropsten and got the abi. The abi looks like this:
abi = [
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_tokenId",
"type": "uint256"
}
],
"name": "approve",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
...
]
I first tried using this like this:
web3 = Web3::Eth::Rpc.new host: 'localhost',
port: 9545,
connect_options: {
use_ssl: false,
read_timeout: 120
}
abi = [...]
@contract = web3.eth.contract(abi);
@contract_instance = @contract.at(CONTRACT_ADDRESS)
But I kept getting the exception RuntimeError: No method found in ABI
.
So I looked at how a contract instance is initialized, I noticed you're expecting abi
to be a single element rather than an array of objects.
Is there anything I'm misunderstanding?
api = Web3::Eth::Etherscan.new 'api_key',
connect_options: {
open_timeout: 10,
read_timeout: 70,
parse_result: true,
url: 'ropsten.etherscan.io/api'
}
api.contract_getabi '0xe3fedaecd47aa8eab6b23227b0ee56f092c967a9'
My code above and get error
Errno::ECONNREFUSED: Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)
from (irb):20
Hi, everyone
I am going to send transfer using ruby.
this is my code.
web3 = Web3::Eth::Rpc.new host: 'ropsten.infura.io',
port: 443,
connect_options: {
open_timeout: 20,
read_timeout: 140,
use_ssl: true,
rpc_path: '/xxxxxxxxxx'
}
ERC_ABI = '[{.....}]'
contractAddr = "0xFf............"
contract = web3.eth.contract(ERC_ABI).at(contractAddr)
data = contract.transfer.getData('0xg.......', 10000, {from: '0xc........'})
but i get some error.
please help me.
Best regards.
Hi there.
I'm trying to get up and running, and I'm doing the following:
web3 = Web3::Eth::Rpc.new host: 'https://mainnet.infura.io', port: 443, connect_options: { open_timeout: 20, read_timeout: 140, use_ssl: true, rpc_path: '/[my api key]' }
I'm getting an instance of web3 back, and when I try to run web3.eth.blockNumber
, I get
SocketError: Failed to open TCP connection to https:443 (getaddrinfo: nodename nor servname provided, or not known)
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.