diff --git a/client/chain/chain.go b/client/chain/chain.go index 7639c95c..e19298fa 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -190,9 +190,14 @@ func NewChainClient( } // init tx factory - txFactory := NewTxFactory(ctx) - if len(opts.GasPrices) > 0 { - txFactory = txFactory.WithGasPrices(opts.GasPrices) + var txFactory tx.Factory + if opts.TxFactory == nil { + txFactory = NewTxFactory(ctx) + if len(opts.GasPrices) > 0 { + txFactory = txFactory.WithGasPrices(opts.GasPrices) + } + } else { + txFactory = *opts.TxFactory } // init grpc connection diff --git a/client/common/options.go b/client/common/options.go index 409bb8f0..59706cd1 100644 --- a/client/common/options.go +++ b/client/common/options.go @@ -3,6 +3,7 @@ package common import ( ctypes "github.com/InjectiveLabs/sdk-go/chain/types" log "github.com/InjectiveLabs/suplog" + "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pkg/errors" "google.golang.org/grpc/credentials" @@ -20,6 +21,7 @@ func init() { type ClientOptions struct { GasPrices string TLSCert credentials.TransportCredentials + TxFactory *tx.Factory } type ClientOption func(opts *ClientOptions) error @@ -52,3 +54,10 @@ func OptionTLSCert(tlsCert credentials.TransportCredentials) ClientOption { return nil } } + +func OptionTxFactory(txFactory *tx.Factory) ClientOption { + return func(opts *ClientOptions) error { + opts.TxFactory = txFactory + return nil + } +} diff --git a/examples/chain/20_MsgExec/example.go b/examples/chain/20_MsgExec/example.go index ae878ac4..6e0d1c03 100644 --- a/examples/chain/20_MsgExec/example.go +++ b/examples/chain/20_MsgExec/example.go @@ -64,11 +64,13 @@ func main() { clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + txFactory := chainclient.NewTxFactory(clientCtx) + txFactory = txFactory.WithGasPrices("500000000inj") chainClient, err := chainclient.NewChainClient( clientCtx, network.ChainGrpcEndpoint, common.OptionTLSCert(network.ChainTlsCert), - common.OptionGasPrices("500000000inj"), + common.OptionTxFactory(&txFactory), ) if err != nil {