onrik / ethrpc Goto Github PK
View Code? Open in Web Editor NEWGolang client for ethereum json rpc api
License: MIT License
Golang client for ethereum json rpc api
License: MIT License
so we can custom http client,
DefaultClient
no timeout, cause my app hangs.
How to use ABI.josn file to call a deployed contract ๏ผ
Please provide an interface to enable mocking the Ethereum RPC client for testing code that uses your package ๐ Like this for example.
Parity returns status: null for transactions before Byzantium. Current code doesn't handle this and will throw calling strconv.ParseInt with null. Maybe we should change this field into *int.
Parity ref: https://wiki.parity.io/JSONRPC-eth-module#eth_gettransactionreceipt
Sample data:
{
"jsonrpc": "2.0",
"result": {
"blockHash": "0xd99ad9a1142e57fbd0aea432bd76ef46c0af1ef71d80b6986b945fce95ce9d34",
"blockNumber": "0x1e8485",
"contractAddress": null,
"cumulativeGasUsed": "0x16d15",
"gasUsed": "0xc905",
"logs": [
{
"address": "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a",
"blockHash": "0xd99ad9a1142e57fbd0aea432bd76ef46c0af1ef71d80b6986b945fce95ce9d34",
"blockNumber": "0x1e8485",
"data": "0x0000000000000000000000000000000000000000000000000000002e90edd000",
"logIndex": "0x0",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000147af46ae9ccd18bb35ca01b353b51990e49dce1",
"0x00000000000000000000000045d01cc478a3dcfd66607726dc50780f3eb4d7bc"
],
"transactionHash": "0x6994e58ca3816889184186ad8883e20277883959084c72a9fe12b92bea6422e2",
"transactionIndex": "0x2",
"transactionLogIndex": "0x0",
"type": "mined"
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000040000000008000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000400010000000000000000000000000000000000000000000000000000000000004000000000000000000800000000000000000000000000000000000000000000000000000000004000002000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000",
"root": "0x5b694615e7e1ff4857d3c0714a4b70133ec2c161e1808029828ef979e5551347",
"status": null,
"transactionHash": "0x6994e58ca3816889184186ad8883e20277883959084c72a9fe12b92bea6422e2",
"transactionIndex": "0x2"
},
"id": 1
}
type TransactionReceipt - not have Status bool
The EthGetBlockByNumber method has the first parameter of type INT.
The first parameter takes a block number.
In the future, this type will create problems with large numbers of blocks that are constantly increasing.
My advice is to use UINT64 or implement your own bigInt type.
hi,i want to use the "eth_sendRawTransaction" method,but i don't understand the "data" parameter inside,How to conduct sign transaction?
client := ethrpc.New("https://ropsten.infura.io")
hash := "0x931084475948fa771429ea3a5c39650e83a95059eff624d2089cc64c21e62915"
bl ,err :=client.EthGetBlockByHash(hash,true)
if err != nil{
log.Print("err", err)
}
fmt.Print("bl---",bl)
Summary
I love your tool. It is very convenient and easy to use. Can you give me an example of EthCall. I got error like the following. The below ethcall is for getting ERC20 token name with the contract address.
Steps to Reproduce
var client *ethrpc.EthRPC
func EthCall() string {
result, err := client.EthCall(ethrpc.T{To: "0x41e5560054824ea6b0732e656e3ad64e20e94e45", Data: "0x06fdde03"}, "latest")
if err != nil {
panic(err)
}
return result
}
Expected Results
Return the result same as normal JSON RPC
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x41e5560054824ea6b0732e656e3ad64e20e94e45","data":"0x06fdde03"}, "latest"],"id":83}' http://localhost:xxxx
{"jsonrpc":"2.0","id":83,"result":"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000054369766963000000000000000000000000000000000000000000000000000000"}
Actual Results
Error occurred.
panic: Error -32602 (invalid argument 0: hex string has length 0, want 40 for common.Address)
Example:eth_getBlockByHash
rpc call return null, if block was not found, which might happen when node is de-synchronised. In this case EthGetBlockByHash api method will return nil error, and empty response. Expected behaviour in this case would be return nil in response.
hi ,is the any advise to call contract ?
TCP will not be released immediately after the end of the access, so when the client opens multiple threads to access at the same time, there will be an error of "onnectex: only one usage of each socket address (protocol/network address/port) is normally allowed." Can we adjust "TIME-WAIT"?
Trying to use the EthSendTransaction() function and having some trouble with the inputs used in the transaction{} object.
It would help alot if you could add an example to the README demonstrating the values used in the transaction{} object and what they represent.
I think there is nothing wrong with the code below as I unlock the account first and then make transaction
package main
import (
"fmt"
"github.com/onrik/ethrpc"
"log"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/accounts"
"math/big"
)
func main() {
client:=ethrpc.New("http://localhost:8545")
_, err := client.Web3ClientVersion()
if err != nil {
log.Fatal("Error Connecting To Node : ",err)
}
ks := keystore.NewKeyStore(
"/home/atif/.ethereum/rinkeby/keystore/",
keystore.LightScryptN,
keystore.LightScryptP)
var unlockedAccount accounts.Account
accs:=ks.Accounts()
if err:=ks.Unlock(accs[1],"abcd");err==nil{
unlockedAccount=accs[1]
fmt.Println("Account Unlocked")
}
t:=ethrpc.T{
From: unlockedAccount.Address.Hex(),
To: "0x92dd679e2d8e107d8122ad5b3c868265e77c8af2",
Gas: 123456,
GasPrice:big.NewInt(12400000),
Value:big.NewInt(20000000000),
Data:"",
Nonce:0,
}
txid, err := client.EthSendTransaction(t)
if err != nil {
log.Fatal("Transaction Error => ",err)
}
fmt.Println(txid)
}
What I want
txid of Real Transaction
What is get
Transaction Error => Error -32000 (authentication needed: password or unlock)
Disclaimer - I'm not super familiar with the Ethereum network
Trying to send a transaction on a private network with EthSendTransaction but getting the following error
Error -32000 (authentication needed: password or unlock)
Is there another function that I should be using that takes a password?
if the transfer is not eth, how to decode input data and get token amount
Just using it as quickly and easily as well.
It looks ethrpc (nice project!) doesn't support a local UNIX socket connection. Would it be possible to add IPC support?
Is there any plan to support ws/wss?
The value returned is incorrect
but response is right
The service gets stuck on rpc call in case of an issue with the node.
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.