func (k KeyringSigner) BuildSignedTx(builder sdkclient.TxBuilder, msg sdktypes.Msg) (authsigning.Tx, error) {
	err := builder.SetMsgs(msg)
	if err != nil {
		return nil, err
	}
	keyInfo, err := k.Key(k.keyringAccName)
	if err != nil {
		return nil, err
	}
	sigV2 := signing.SignatureV2{
		PubKey: keyInfo.GetPubKey(),
		Data: &signing.SingleSignatureData{
			SignMode:  signing.SignMode_SIGN_MODE_DIRECT,
			Signature: nil,
		},
		Sequence: k.sequence,
	}
	err = builder.SetSignatures(sigV2)
	if err != nil {
		return nil, err
	}
	bytesToSign, err := k.encCfg.TxConfig.SignModeHandler().GetSignBytes(
		signing.SignMode_SIGN_MODE_DIRECT,
		authsigning.SignerData{
			ChainID:       k.chainID,
			AccountNumber: k.accountNumber,
			Sequence:      k.sequence,
		},
		builder.GetTx(),
	)
	if err != nil {
		return nil, err
	}
	sigBytes, _, err := k.SignByAddress(keyInfo.GetAddress(), bytesToSign)
	if err != nil {
		return nil, err
	}
	sigV2 = signing.SignatureV2{
		PubKey: keyInfo.GetPubKey(),
		Data: &signing.SingleSignatureData{
			SignMode:  signing.SignMode_SIGN_MODE_DIRECT,
			Signature: sigBytes,
		},
		Sequence: k.sequence,
	}
	err = builder.SetSignatures(sigV2)
	if err != nil {
		return nil, err
	}
	return builder.GetTx(), nil
}
BuildSignedTx creates and signs a sdk.Tx that contains the provided message. The interal
account number must be set by calling k.QueryAccountNumber or by manually setting it via
k.SetAccountNumber for the built transactions to be valid.
package types
import (
	"context"
	sdkclient "github.com/cosmos/cosmos-sdk/client"
	"github.com/cosmos/cosmos-sdk/crypto/keyring"
	sdktypes "github.com/cosmos/cosmos-sdk/types"
	"github.com/cosmos/cosmos-sdk/types/tx"
	"github.com/cosmos/cosmos-sdk/types/tx/signing"
	authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
	authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
	"github.com/tendermint/spm/cosmoscmd"
	"google.golang.org/grpc"
)
type KeyringSigner struct {
	keyring.Keyring
	keyringAccName string
	accountNumber  uint64
	sequence       uint64
	chainID        string
	encCfg         cosmoscmd.EncodingConfig
}
func NewKeyringSigner(ring keyring.Keyring, name string, chainID string) *KeyringSigner {
	return &KeyringSigner{
		Keyring:        ring,
		keyringAccName: name,
		chainID:        chainID,
		encCfg:         makeEncodingConfig(),
	}
}
func (k *KeyringSigner) QueryAccountNumber(ctx context.Context, conn *grpc.ClientConn) error {
	info, err := k.Key(k.keyringAccName)
	if err != nil {
		return err
	}
	accNum, seqNumb, err := QueryAccount(ctx, conn, k.encCfg, info.GetAddress().String())
	if err != nil {
		return err
	}
	k.accountNumber = accNum
	k.sequence = seqNumb
	return nil
}
func (k KeyringSigner) NewTxBuilder() sdkclient.TxBuilder {
	return k.encCfg.TxConfig.NewTxBuilder()
}