Hot answers tagged

28

Every programming language is designed for a particular operational environment and target tasks; and these constraints drive almost all design decisions on what features to support and which ones to drop. A while ago I've spent quite a lot of time to create a Go -> EVM cross compiler. I did manage to run a few trivial programs and it definitely was a lot ...


11

Recently, there are so many people confused about miner.start(1) returning null, but it's actually not a problem, just a reasonable return value misunderstanding. If you aren't sure that your node is mining, please execute eth.hashrate to check, if the return value is greater than zero, it is mining, otherwise, it is not. Now let's analyze why miner.start(...


11

Let's start with having a look at what we get in geth console for block number 40. Now let's consider a Go program. I Explained everything in code comments about how it is constructing keys and accessing values from Leveldb. package main import ( "github.com/syndtr/goleveldb/leveldb" "fmt" "encoding/binary" "github.com/ethereum/go-...


7

go-ethereum abi package in Oct 2017 got the update to unpack event output. Initially it was only able to unpack method output. All functionality is delivered through the abi.ABI object. To use it you need to have Event ABI (JSON string). Then use func (abi *ABI) UnmarshalJSON to construct the ABI object. From there you can use the Unpack method using Data ...


7

Using node hex in nodekey file under .ethereum/geth/nodekey and bootnode utility. Assuming you are using Linux. Check your nodekey hex : $ cat ~/.ethereum/geth/nodekey 2ad3a9ccd99926514e77501c33c5fdbae6ecfdc6fc82853bc8f28772b13cd2df Then with bootnode utility : $ bootnode -nodekeyhex 2ad3a9ccd99926514e77501c33c5fdbae6ecfdc6fc82853bc8f28772b13cd2df -...


5

try setting miner.setEtherbase(eth.coinbase) or step by step: start Mist browser (let the node synchronize completely) open console and type: geth attach miner.setEtherbase(eth.accounts[0]) miner.start() Even if it returns null you can see in the buttom left corner of Mist broser, that mining has startet. It takes a while till the hashrate incrases. You ...


5

Here's a full code example for anyone who's still confused (thanks to @Robert Zaremba's answer) package main import ( "context" "log" "math/big" "strings" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/myorg/myrepo/go-contracts/token" ...


5

I can only give you a general guide on how to do this: 1) Modify core/vm/instructions.go to add your instruction code, something like: func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(math.U256(x.Add(x, y))) evm.interpreter.intPool.put(y) ...


4

The answer to the question in the title is no, it is not possible to create a hash in Solidity that you are sure will be unique, at least given the possibility of block orphaning and reorgs. Users can pass a nonce into the transaction, but unless you trust them, you can't be sure they won't pass the same one in twice. If you're making your ID entirely ...


4

Check Open File Descriptor Limits You may need to increase the Linux file limit to handle the number of connections your nodes are serving. Here are some articles on checking and setting the limits. There are hard and soft, system wide and per user limits. To check the maximum number of file descriptors configured on your Linux system: user@Kumquat:~$ cat ...


4

Not yet. We've just revamped the server side RPC internals in develop and are still ironing out some quirks. I can imagine we would soon-ish start working towards the directions of providing some Go client APIs, but we're not there yet. If you just need a few specific ones, they are relatively easy to implement (here's a few we needed for a hackathon last ...


4

You might take a look at a simplistic approach we took for etherapis: https://github.com/etherapis/etherapis/blob/master/etherapis/geth/api.go However there's an RPC client in the works that should already support subscriptions too. Not sure when Felix will open his PR with it though.


4

You can use the package github.com/miguelmota/go-ethereum-hdwallet to implement an HD wallet (which implements the accounts.Wallet interface from go-ethereum). Here's a basic example to get started: import ( "fmt" "log" "github.com/miguelmota/go-ethereum-hdwallet" "github.com/tyler-smith/go-bip39" ) func main() { entropy, err := bip39....


4

to convert from binary to hex, and back, use the package encoding/hex Hex ==> string: str := hex.EncodeToString(**your slice of bytes**) Hex <== string: b, err := hex.DecodeString(**your string**)


3

One of the Golang gurus might want to comment further, but I don't think Go supports 256-bit integers natively. You could import Geth's number package, together with math/big, and use the relevant parts. e.g. Call Uint256(): // Return a Number with a UNSIGNED limiter up to 256 bits func Uint256(n int64) *Number { return &Number{big.NewInt(n), ...


3

I don't have the solution for your code because I haven't looked into using the go-ethereum internals to do RPC calls but I've made a very small rpc client library you can find on my github that uses gorequest and simplejson ( I'm no go expert ;) ) There's also the "main" file where I started to wrap the calls by going to a more well defined api, you can ...


3

I made it work by adding a true parameter in err = client.Call(&lastBlock, "eth_getBlockByNumber", "latest", true) and changing *bit.Int to string Like this: package main import( "fmt" "log" "github.com/ethereum/go-ethereum/rpc" ) type Block struct { Number string } func main() { // Connect the client client, err := rpc.Dial("...


3

First don't mix Go as the language used for building some Ethereum tools and base implementation and languages for writing smart contracts such as solidity that can be compiled into evm code. Today i'm not aware of any evm compiler that would be able to use Go code as input or a mix of Go and Solidity. But you can imagine one as some are able to use ...


3

First make sure you have the latest version, EAP 15, 173.2696.28, and you are using the latest version of Go, 1.9, as that's preferred for a better debugging experience due to the recent improvements in Go with regards to debugging. Then, go to Run | Edit Configurations | Go Applications | select the run configuration you want to edit | Run kind and change ...


3

The error comes from the json unmarshaller. The Receipt provides the UnmarshalJSON method which is used by the json std lib to decode the bytes. If we look at the method definition we can see that: it is using a different local Receipt type to do automatic decoding. the local type has field PostState hexutil.Bytes which maps to the "root" JSON key (look ...


3

The problem is that the setting of GOPATH is incorrect. You need to set the GOPATH in the IDE to: /home/robert/go and then open the project via Open Directory to /home/robert/go/src/github.com/ethereum/go-ethereum. See the Go Workspace for how to set up a Go workspace.


3

Make sure your gopath is correct export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin Install abigen go get -u github.com/ethereum/go-ethereum cd $GOPATH/src/github.com/ethereum/go-ethereum/ make make devtools Compile abi solc --abi MyContract.sol | awk '/JSON ABI/{x=1;next}x' > MyContract.abi solc --bin MyContract.sol | awk '/Binary:/{x=1;next}x' &...


3

I can't tell you why the ethclient.EstimateGas underreports the consumed gas. I remember facing the same problem once and my lazy solution was to multiply whatever it reported by 3. In order to calculate the correct gas price for a method call, you need the binary EVM code of the contract. Once you have that, you can look up the price of each instruction in ...


3

One of the binaries that can be generated by the go ethereum implementation is bootnode that can be used (as the name suggests) to create a bootnode, i.e. a node that is involved only in the p2p management. You can exploit this tool to generate a new id for the node: bootnode -genkey <your-node-key-file> Afterward you can use this file with geth: ...


3

You only need the public key in bytes format which means you don't need the private key at all and don't need the key in ecdsa type either. For example: publicKeyBytes, err := hex.DecodeString("049a7df67f79246283fdc93af76d4f8cdd62c4886e8cd870944e817dd0b97934fdd7719d0810951e03418205868a5c1b40b192451367f28e0088dd75e15de40c05") sigPublicKey, err := crypto....


3

Here's an example of how to invoke a smart contract method in Go. This should give you an idea of how to go about it. MyContract.sol example contract pragma solidity >=0.4.21 <0.6.0; contract MyContract { function transfer(address payable recipient, uint256 amount) public { // your code } } Generate ABI using solc and Go package using ...


3

That opcode is a recent addition to geth in the Constantinople release. You need to add the following to your genesis to enable Constantinople: "constantinopleBlock":0,


3

This is basically down to the interpretation of your input data as bytes or as a string. A good way to test this is using web3 in a browser (eg just visit the remix site and there's a console window you can use. This shows the following: > web3.utils.keccak256("...


2

The go-ethereum package provides a common.LeftPadBytes function for left padding values for solidity. You'd use this to pad to 32 bytes which is the word size the EVM uses. Here's a full example of how to manually construct the transaction data for transferring an ERC-20 token which should give you an good idea (from the Ethereum Development with Go book). ...


Only top voted, non community-wiki answers of a minimum length are eligible