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

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-...


9

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(...


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 -...


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

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 ...


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

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


4

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) ...


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

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

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

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....


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

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

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

One place to start from would be NewTransaction() in transaction.go. This is part of the types package. // NewTransaction creates a new transaction with the given properties. func NewTransaction(nonce int64, to *Address, amount, gasLimit, gasPrice *BigInt, data []byte) *Transaction { return &Transaction{types.NewTransaction(uint64(nonce), to.address,...


2

If the hash doesn't need to be perfectly random, instead you just want some guaranteed unique ID, you could sha3 a nonce or to be more abstract, with concatenation of data that's been sent with the transaction. uint nonce; ... bytes32 unique = sha3(block.number, msg.data, nonce++)` It depends on what properties you need in the resulting hash. sha3 can be ...


2

You can theoretically write smart contracts in any language you like, but you'd also need to write a compiler to create bytecode that the EVM was able to understand. In the past there was a Go-like/C-like language called Mutan, which is now deprecated. I don't believe anyone has written a compiler for pure Go, and the following thread makes some ...


2

A two-part answer. "you need to loop": This just jumps out at me and deserves a comment. Smart Contracts don't give you indexed storage but this doesn't imply that a contract should loop over disorganized data. In fact, contracts must not loop over unbounded sets. Instead, it means that contracts are responsible for organizing data internally. Organize ...


2

As discussed here, I think rpc.NewIPCClient is deprecated and replaced by rpc.Dial("****"). herefore, you can use : client = ethclient.Dial("http://*.*.*.*:8545"). From this example you'll find this snippet code: func getBalance(address common.Address) { client, err := ethclient.Dial("http://localhost:8545") if err != nil { fmt.Printf("%...


2

abigen supports variables too - but as functions, from my current code mapping (address => uint256) public deposits; translates to func (_HelloGoldSale *HelloGoldSaleCaller) Deposits(opts *bind.CallOpts, arg0 common.Address) (*big.Int, error) which you can call via dep, err := saleObject.Deposits(nil,myAddress)


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