5

So I'm learning more about Ethereum, and I wrote this gist in Go to start interacting with geth nodes and publishing transactions to the network. I'm getting an error that says:

panic: invalid transaction v, r, s values

Here's the code I wrote to send the transaction: https://gist.github.com/karysto/3c7c1ab9d3ae736e5c63a2bbe4c47ac2

Any and all help appreciated!

Update: It seems that the network/signer chain id is being mis-set somewhere. Despite the fact that I'm setting the chain id to 0 in the gist, the chain id for a transaction always gets set to 9223372036854775790. My guess is the transaction is getting signed correctly but is getting signed with the incorrect chain (the one above), hence the invalid v,r,s error. If someone knows a way to fix this issue or finds I'm incorrect, don't hesitate to submit an answer!

Update: March 29 2017: I opened an issue on Go ethereum explaining this problem.

Geth versions tested: 1.5.9 and 1.6.0-unstable

  • what do you mean by this "Despite the fact that I'm setting the chain id in the genesis block and the gist to 0"? – vutran Mar 29 '17 at 1:01
  • My mistake, the chain id is only set in the gist I linked, not the genesis block. Updated the question. – delos Mar 29 '17 at 1:06
3

I don't know if this will help in any way at all but I had something I wrote just before abigen was introduced. I have tried to keep it updated (no 100% guarantee)

github.com/DaveAppleton/ether_go

Maybe it will help

1

Here's a full example of how to sign a transaction and broadcast in Go (from the Ethereum Development with Go book).

package main

import (
    "context"
    "crypto/ecdsa"
    "fmt"
    "log"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/core/types"
    "github.com/ethereum/go-ethereum/crypto"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://rinkeby.infura.io")
    if err != nil {
        log.Fatal(err)
    }

    privateKey, err := crypto.HexToECDSA("fad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19")
    if err != nil {
        log.Fatal(err)
    }

    publicKey := privateKey.Public()
    publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
    if !ok {
        log.Fatal("error casting public key to ECDSA")
    }

    fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
    nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
    if err != nil {
        log.Fatal(err)
    }

    value := big.NewInt(1000000000000000000) // in wei (1 eth)
    gasLimit := uint64(21000)                // in units
    gasPrice := big.NewInt(30000000000)      // in wei (30 gwei)

    toAddress := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
    var data []byte
    tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data)
    signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, privateKey)
    if err != nil {
        log.Fatal(err)
    }

    err = client.SendTransaction(context.Background(), signedTx)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("tx sent: %s", signedTx.Hash().Hex())
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.