Documentation ¶
Overview ¶
Example (ReadOnly) ¶
Example_readOnly demonstrates how to initialize a read-only gnoclient, which can only query.
package main import ( "github.com/gnolang/gno/gno.land/pkg/gnoclient" rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" ) func main() { remote := "127.0.0.1:26657" rpcClient, _ := rpcclient.NewHTTPClient(remote) client := gnoclient.Client{ RPCClient: rpcClient, } _ = client }
Output:
Example (WithDisk) ¶
Example_withDisk demonstrates how to initialize a gnoclient with a keybase sourced from a directory.
package main import ( "github.com/gnolang/gno/gno.land/pkg/gnoclient" rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" "github.com/gnolang/gno/tm2/pkg/crypto/keys" ) func main() { kb, _ := keys.NewKeyBaseFromDir("/path/to/dir") signer := gnoclient.SignerFromKeybase{ Keybase: kb, Account: "mykey", Password: "secure", } remote := "127.0.0.1:26657" rpcClient, _ := rpcclient.NewHTTPClient(remote) client := gnoclient.Client{ Signer: signer, RPCClient: rpcClient, } _ = client }
Output:
Example (WithInMemCrypto) ¶
Example_withInMemCrypto demonstrates how to initialize a gnoclient with an in-memory keybase using BIP39 mnemonics.
package main import ( "github.com/gnolang/gno/gno.land/pkg/gnoclient" rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" ) func main() { mnemo := "index brass unknown lecture autumn provide royal shrimp elegant wink now zebra discover swarm act ill you bullet entire outdoor tilt usage gap multiply" bip39Passphrase := "" account := uint32(0) index := uint32(0) chainID := "dev" signer, _ := gnoclient.SignerFromBip39(mnemo, chainID, bip39Passphrase, account, index) remote := "127.0.0.1:26657" rpcClient, _ := rpcclient.NewHTTPClient(remote) client := gnoclient.Client{ Signer: signer, RPCClient: rpcClient, } _ = client }
Output:
Index ¶
- Variables
- func NewAddPackageTx(cfg BaseTxCfg, msgs ...vm.MsgAddPackage) (*std.Tx, error)
- func NewCallTx(cfg BaseTxCfg, msgs ...vm.MsgCall) (*std.Tx, error)
- func NewRunTx(cfg BaseTxCfg, msgs ...vm.MsgRun) (*std.Tx, error)
- func NewSendTx(cfg BaseTxCfg, msgs ...bank.MsgSend) (*std.Tx, error)
- type BaseTxCfg
- type Client
- func (c *Client) AddPackage(cfg BaseTxCfg, msgs ...vm.MsgAddPackage) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *Client) Block(height int64) (*ctypes.ResultBlock, error)
- func (c *Client) BlockResult(height int64) (*ctypes.ResultBlockResults, error)
- func (c *Client) BroadcastTxCommit(signedTx *std.Tx) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *Client) Call(cfg BaseTxCfg, msgs ...vm.MsgCall) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *Client) LatestBlockHeight() (int64, error)
- func (c *Client) QEval(pkgPath string, expression string) (string, *ctypes.ResultABCIQuery, error)
- func (c *Client) Query(cfg QueryCfg) (*ctypes.ResultABCIQuery, error)
- func (c *Client) QueryAccount(addr crypto.Address) (*std.BaseAccount, *ctypes.ResultABCIQuery, error)
- func (c *Client) QueryAppVersion() (string, *ctypes.ResultABCIQuery, error)
- func (c *Client) Render(pkgPath string, args string) (string, *ctypes.ResultABCIQuery, error)
- func (c *Client) Run(cfg BaseTxCfg, msgs ...vm.MsgRun) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *Client) Send(cfg BaseTxCfg, msgs ...bank.MsgSend) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *Client) SignTx(tx std.Tx, accountNumber, sequenceNumber uint64) (*std.Tx, error)
- type QueryCfg
- type SignCfg
- type Signer
- type SignerFromKeybase
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidGasWanted = errors.New("invalid gas wanted") ErrInvalidGasFee = errors.New("invalid gas fee") ErrMissingSigner = errors.New("missing Signer") ErrMissingRPCClient = errors.New("missing RPCClient") )
var ErrInvalidBlockHeight = errors.New("invalid block height provided")
Functions ¶
func NewAddPackageTx ¶
NewAddPackageTx makes an unsigned transaction from one or more MsgAddPackage. The Creator field must be set.
func NewCallTx ¶
NewCallTx makes an unsigned transaction from one or more MsgCall. The Caller field must be set.
Types ¶
type BaseTxCfg ¶
type BaseTxCfg struct { GasFee string // Gas fee GasWanted int64 // Gas wanted AccountNumber uint64 // Account number SequenceNumber uint64 // Sequence number Memo string // Memo }
BaseTxCfg defines the base transaction configuration, shared by all message types
type Client ¶
type Client struct { Signer Signer // Signer for transaction authentication RPCClient rpcclient.Client // RPC client for blockchain communication }
Client provides an interface for interacting with the blockchain.
func (*Client) AddPackage ¶
func (c *Client) AddPackage(cfg BaseTxCfg, msgs ...vm.MsgAddPackage) (*ctypes.ResultBroadcastTxCommit, error)
AddPackage executes one or more AddPackage calls on the blockchain
func (*Client) Block ¶
func (c *Client) Block(height int64) (*ctypes.ResultBlock, error)
Block gets the latest block at height, if any Height must be larger than 0
func (*Client) BlockResult ¶
func (c *Client) BlockResult(height int64) (*ctypes.ResultBlockResults, error)
BlockResult gets the block results at height, if any Height must be larger than 0
func (*Client) BroadcastTxCommit ¶
BroadcastTxCommit marshals and broadcasts the signed transaction, returning the result. If the result has a delivery error, then return a wrapped error.
func (*Client) LatestBlockHeight ¶
LatestBlockHeight gets the latest block height on the chain
func (*Client) QEval ¶
QEval evaluates the given expression with the realm code at pkgPath. The pkgPath should include the prefix like "gno.land/". The expression is usually a function call like "GetBoardIDFromName(\"testboard\")". The return value is a typed expression like "(1 gno.land/r/demo/boards.BoardID)\n(true bool)".
func (*Client) Query ¶
func (c *Client) Query(cfg QueryCfg) (*ctypes.ResultABCIQuery, error)
Query performs a generic query on the blockchain.
func (*Client) QueryAccount ¶
func (c *Client) QueryAccount(addr crypto.Address) (*std.BaseAccount, *ctypes.ResultABCIQuery, error)
QueryAccount retrieves account information for a given address.
func (*Client) QueryAppVersion ¶
func (c *Client) QueryAppVersion() (string, *ctypes.ResultABCIQuery, error)
QueryAppVersion retrieves information about the app version
func (*Client) Render ¶
Render calls the Render function for pkgPath with optional args. The pkgPath should include the prefix like "gno.land/". This is similar to using a browser URL <testnet>/<pkgPath>:<args> where <pkgPath> doesn't have the prefix like "gno.land/".
type QueryCfg ¶
type QueryCfg struct { Path string // Query path Data []byte // Query data rpcclient.ABCIQueryOptions // ABCI query options }
QueryCfg contains configuration options for performing ABCI queries.
type SignCfg ¶
SignCfg provides the signing configuration, containing: unsigned transaction data, account number, and account sequence.
type Signer ¶
type Signer interface { Sign(SignCfg) (*std.Tx, error) // Signs a transaction and returns a signed tx ready for broadcasting. Info() (keys.Info, error) // Returns key information, including the address. Validate() error // Checks whether the signer is properly configured. }
Signer provides an interface for signing transactions.
func SignerFromBip39 ¶
func SignerFromBip39(mnemonic string, chainID string, passphrase string, account uint32, index uint32) (Signer, error)
SignerFromBip39 creates a signer from an in-memory keybase with a single default account, derived from the given mnemonic. This can be useful in scenarios where storing private keys in the filesystem isn't feasible.
Warning: Using keys.NewKeyBaseFromDir to get a keypair from local storage is recommended where possible, as it is more secure.
type SignerFromKeybase ¶
type SignerFromKeybase struct { Keybase keys.Keybase // Stores keys in memory or on disk Account string // Account name or bech32 format Password string // Password for encryption ChainID string // Chain ID for transaction signing }
SignerFromKeybase represents a signer created from a Keybase.
func (SignerFromKeybase) Info ¶
func (s SignerFromKeybase) Info() (keys.Info, error)
Info gets keypair information.
func (SignerFromKeybase) Sign ¶
func (s SignerFromKeybase) Sign(cfg SignCfg) (*std.Tx, error)
Sign implements the Signer interface for SignerFromKeybase.
func (SignerFromKeybase) Validate ¶
func (s SignerFromKeybase) Validate() error
Validate checks if the signer is properly configured.