Transaction loses signer info when being sent to the server #12007
-
I'm trying to send a vote transaction programatically. I have something like this import (
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/simapp"
txTypes "github.com/cosmos/cosmos-sdk/types/tx"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
...
)
kr := keyring.NewInMemory()
// import keys...
encCfg := simapp.MakeTestEncodingConfig()
govTypes.RegisterInterfaces(encCfg.InterfaceRegistry)
txConf := encCfg.TxConfig
txf := tx.Factory{}.
WithTxConfig(txConf).
WithKeybase(kr).
WithChainID("...").
WithGasPrices("...").
WithGasAdjustment(...).
WithGas(...)
txBuilder, err := tx.BuildUnsignedTx(txf)
handleError(err)
voteMsg := govTypes.NewMsgVote(k.GetAddress(), ..., govTypes.OptionYes)
err = voteMsg.ValidateBasic()
handleError(err)
txBuilder.SetMsgs(voteMsg)
err = tx.Sign(txf, "owner_key", txBuilder, true)
handleError(err)
actualTx := txBuilder.GetTx()
txBytes, err := txConf.TxEncoder()(actualTx)
handleError(err)
// this prints the signed transaction bytes
fmt.Println(txBytes)
if nodeURI != "" {
err := grpcSend(nodeURI, txBytes)
handleError(err)
} The func grpcSend(nodeURI string, txBytes []byte) error {
grpcConn, err := grpc.Dial(
nodeURI,
grpc.WithInsecure(),
)
if err != nil {
return err
}
defer grpcConn.Close()
txClient := txTypes.NewServiceClient(grpcConn)
res, err := txClient.BroadcastTx(context.Background(), &txTypes.BroadcastTxRequest{
Mode: txTypes.BroadcastMode_BROADCAST_MODE_SYNC,
TxBytes: txBytes,
})
if err != nil {
return err
}
fmt.Println(res.TxResponse.Code)
fmt.Println(res.TxResponse.RawLog)
return nil
} The transaction gets built and signed and everything is fine up until the moment I send the transaction and get a response The response says
Looks like this response is coming from this section of the code cosmos-sdk/x/auth/ante/sigverify.go Lines 79 to 80 in a3a0124 I tried to simulate the thing that it's doing locally by decoding decodedTx, err := txConf.TxDecoder()(txBytes)
handleError(err)
stx, ok := decodedTx.(authsigning.SigVerifiableTx)
handleError(err)
fmt.Println(stx.GetSigners()[0]) but it gets printed fine Looks like something gets lost specifically when it's being sent over GRPC. not sure Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
if err = tx.Sign(txf, clientCtx.GetFromName(), unsignedTx, true); err != nil {
return nil, err
}
txBytes, err := clientCtx.TxConfig.TxEncoder()(unsignedTx.GetTx())
if err != nil {
return nil, err
}
return clientCtx.BroadcastTx(txBytes) Is the correct way to do it, which is what you seem to be doing as well...so I'm not sure what's going on. Thoughts @AmauryM ? |
Beta Was this translation helpful? Give feedback.
-
We are trying to use TypeScript SDKs and encountering this error. Would switching to Go solve this issue? Could anyone provide guidance or assistance with this? We're encountering the error "pubKey does not match signer address inj1... with signer index: 0: invalid pubkey" when attempting to send a transaction. We're retrieving both the public key and address from the same wallet. The address derived from the public key matches the address directly fetched from the wallet. |
Beta Was this translation helpful? Give feedback.
Is the correct way to do it, which is what you seem to be doing as well...so I'm not sure what's going on. Thoughts @AmauryM ?