2

I tried to send a tx via geth json rpc using the following code. But the geth rpc server response with "Invalid sender". I also tried HomesteadSigner. In that case there is no error received, but I cannot find the receipt for the transaction, no matter how long I wait. Is there anything wrong? thx for any recommendation

KeystoreDir := "D:\\work\\src\\b710cd2a24e0a6dfdc078df50ea42fc2b8d67fcf"

keyjson, err := ioutil.ReadFile(KeystoreDir)
if err != nil {
    log.Fatal(err)
}
password := "test"
key, err := accounts.DecryptKey(keyjson, password)
if err != nil {
    log.Fatal("Json key decrypted with bad password")
}

tx := types.NewTransaction(5, addrReceiver, amount, gasLimit, gasPrice, nil)
tx, err = tx.SignECDSA(types.NewEIP155Signer(big.NewInt(1)), key.PrivateKey) //types.HomesteadSigner{}
if err != nil {
    return err
}
_, err = types.Sender(types.NewEIP155Signer(big.NewInt(1)), tx)
if err != nil {
    log.Fatal("Network ID fault")
}

err = client.SendTransaction(ctx, tx)
if err != nil {
    log.Fatalf("Tx Error: %s %x %x %d\n", err, addrSender, addrReceiver, balance.Div(balance, common.Finney))
}
0

You can try to change the chainID big.NewInt(1) in types.NewEIP155Signer(big.NewInt(1)), key.PrivateKey) it has to be the same as the node network id.

For example it should be big.NewInt(15) if geth --networkid 15 is launched

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.