1

I'd love to switch from JS to Go on our back-end, but the constant development of web3 is such a boon. I can see some web3 wrappers for Gopherjs, and of course it's easy to do direct RPC calls with Go, but is there another way?

EDIT: Here's how.

You want to use the Go-Ethereum client directly at http://github.com/ethereum/go-ethereum , and instantiate their Ethclient struct. It has RPC methods written for you. Here's an example:

    client, err := ethclient.Dial("https://ipaddress-to-infura-or-something") // instantiate a new RPC connection
    var parsedTx types.Transaction // types.Transaction is also from the go-ethereum library
    err = json.Unmarshal([]byte(tx.SignedTransaction.String), &parsedTx) // this part is more specific to my use case, but I basically have a signed transaction in RLP encoded form that Im sending in as data for my RPC call.
    if err != nil {
        return err
    }
    err = client.SendTransaction(context.TODO(), &parsedTx) // here I actually call the SendTransaction function, which is like eth_sendRawTransaction RPC opcode.
    if err != nil {
        return err
    }

More info on whats available here: https://github.com/ethereum/wiki/wiki/JSON-RPC

Here is the Ethclient code itself: https://github.com/ethereum/go-ethereum/blob/master/ethclient/ethclient.go

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.