Documentation ¶
Index ¶
- type Client
- func (receiver Client) Call(methodname string, parameters ...interface{}) ([]interface{}, error)
- func (receiver Client) Chain10Exponent() (uint64, bool)
- func (receiver Client) ChainCode() string
- func (receiver Client) ChainID() uint64
- func (receiver Client) ChainName() string
- func (receiver Client) ContractAddress() ethaddr.Address
- func (receiver Client) CurrentBlockNumber() (*big.Int, error)
- type Contract
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for a smart-contract on some blockchain-network.
To create a new conclient.Client, use conclient.Make. For example:
client := conclient.MakeClient(contract, rpcurl)
func MakeClient ¶
MakeClient makes a conclient.Client for contract 'Contract' using RPC-URL 'rpcurl'.
Example:
client := conclient.MakeClient(contract, rpcurl)
func (Client) Chain10Exponent ¶
Chain10Exponent returns the exponent of the blockchain-network this client is attached to.
The 'exponent' comes from the following equation that shows up the default-currency-code relates to the smallest-currency-code:
1 [DEFAULT-CURRENCY-CODE] = 10ⁿ [SMALLEST-CURRENCY-CODE]
(Where "n" is the value that Chain10Exponent returns.)
For example, on Ethereum:
1 ETH = 1,000,000,000,000,000,000 wei = 10¹⁸ wei
Therefore Chain10Exponent would return: 18
And also, for example, on Avalanche:
1 AVAX = 1,000,000,000 nanoAVAX = 10⁹ nanoAVAX
Therefore Chain10Exponent would return: 9
The reason this number is useful is this —
Often you will be working with numbers that aer in the smallest-currency of the blockchain-network. (Ex: "wei" rather than "ETH".) But you need to display things in the default-currency. (Ex: "ETH" rather than "wei".) So you need to do a conversion. (Ex: convert "wei" to "ETH".) The number Chain10Exponent returns will enable you to do that conversion.
For example:
var chainid uint64 = // ... // ... var wei *big.Int = // ... // ... var exponent *big.Int = new(big.Int).SetUint64( chain10.Exponent(chainid) ) var conversionDenominator *big.Int = new(big.Int).Exp(10, exponent) var ethrat *big.Rat = new(big.Rat).SetFrac(wei, conversionDenominator) var eth *big.Float = new(big.Float).SetRat(ethrat)
func (Client) ChainCode ¶
ChainCode returns the (curency) chain-code of the blockchain-network this client is attached to.
See https://chainlist.org/ for the list of chain-ids mapped to (currency) chain-codes.
func (Client) ChainID ¶
ChainID returns the chain-id of the blockchain-network this client is attached to.
See https://chainlist.org/ for the list of chain-ids.
func (Client) ChainName ¶
ChainName returns the (human-legible) chain-name of the blockchain-network this client is attached to.
See https://chainlist.org/ for the list of chain-ids mapped to chain-names.
func (Client) ContractAddress ¶
func (receiver Client) ContractAddress() ethaddr.Address
func (Client) CurrentBlockNumber ¶
CurrentBlockNumber returns the current (newest) block-number for the blockchain-network which this client is conencted to.
Each blockchain-network will (likely) have a different current (newest) blockchain-number.
And each blockchain-network's current (newest) block-number will change over time.
Example:
currentBlockNumber, err := client.CurrentBlockNumber()