Documentation ¶
Index ¶
- Variables
- func ABIBuiltIn(abiFile string) (*abi.ABI, error)
- func ABIOpenFile(abiFile string) (*abi.ABI, error)
- func ABIOpenURL(abiFile string) (*abi.ABI, error)
- func Base(b int64) *big.Int
- func CallConstantFunction(ctx context.Context, client Client, myabi abi.ABI, address string, ...) ([]interface{}, error)
- func CompileSolidityString(ctx context.Context, source, solcVersion, evmVersion string, optimize bool) (map[string]*Contract, error)
- func ConvertArgument(abiType abi.Type, param interface{}) (interface{}, error)
- func ConvertArguments(args abi.Arguments, params []interface{}) ([]interface{}, error)
- func ConvertInt(signed bool, size int, i *big.Int) (interface{}, error)
- func DecToInt(d decimal.Decimal, decimals int32) *big.Int
- func FindEventById(abi abi.ABI, id common.Hash) *abi.Event
- func FloatAsInt(amountF *big.Float, decimals int) *big.Int
- func GetABI(abiFile string) (*abi.ABI, error)
- func Gwei(g int64) *big.Int
- func IntAsFloat(i *big.Int, decimals int) *big.Float
- func IntToDec(i *big.Int, decimals int32) decimal.Decimal
- func ParseAmount(amount string) (*big.Int, error)
- func ParseBase(b string) (*big.Int, error)
- func ParseBigInt(value string) (*big.Int, error)
- func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion string, ...) (map[string]*Contract, error)
- func ParseGwei(g string) (*big.Int, error)
- func SendTransaction(ctx context.Context, client Client, signedTx *types.Transaction) error
- func WeiAsBase(w *big.Int) string
- func WeiAsGwei(w *big.Int) string
- type Account
- type Block
- type CallMsg
- type Client
- type Contract
- type ContractInfo
- type Event
- type ID
- type Network
- type Receipt
- type Snapshot
- type Solidity
- type Tally
- type Transaction
- func CallFunctionWithArgs(ctx context.Context, client Client, privateKeyHex, address string, ...) (*Transaction, error)
- func CallFunctionWithData(ctx context.Context, client Client, privateKeyHex, address string, ...) (*Transaction, error)
- func CallTransactFunction(ctx context.Context, client Client, myabi abi.ABI, ...) (*Transaction, error)
- func DeployBin(ctx context.Context, client Client, ...) (*Transaction, error)
- func DeployContract(ctx context.Context, client Client, privateKeyHex string, ...) (*Transaction, error)
- func Send(ctx context.Context, client Client, privateKeyHex string, ...) (*Transaction, error)
- type Vote
Constants ¶
This section is empty.
Variables ¶
var Networks = map[string]Network{ "testnet": { Name: "testnet", URL: testnetURL, ChainID: big.NewInt(31337), Unit: "GO", ExplorerURL: testnetExplorerURL, }, "gochain": { Name: "gochain", URL: mainnetURL, ChainID: big.NewInt(60), Unit: "GO", ExplorerURL: mainnetExplorerURL, }, "localhost": { Name: "localhost", URL: "http://localhost:8545", Unit: "GO", }, "ethereum": { Name: "ethereum", URL: "https://mainnet.infura.io/v3/bc5b0e5cfd9b4385befb69a68a9400c3", ChainID: big.NewInt(1), Unit: "ETH", ExplorerURL: "https://etherscan.io", }, "ropsten": { Name: "ropsten", URL: "https://ropsten-rpc.linkpool.io", ChainID: big.NewInt(3), Unit: "ETH", }, }
var NotFoundErr = errors.New("not found")
Functions ¶
func CallConstantFunction ¶
func CallConstantFunction(ctx context.Context, client Client, myabi abi.ABI, address string, functionName string, params ...interface{}) ([]interface{}, error)
CallConstantFunction executes a contract function call without submitting a transaction.
func CompileSolidityString ¶
func CompileSolidityString(ctx context.Context, source, solcVersion, evmVersion string, optimize bool) (map[string]*Contract, error)
CompileSolidityString builds and returns all the contracts contained within a source string.
func ConvertArgument ¶
ConvertArgument attempts to convert argument to the provided ABI type and size. Unrecognized types are passed through unmodified.
func ConvertArguments ¶
ConvertArguments attempts to convert each param to the matching args type. Unrecognized param types are passed through unmodified.
Note: The encoding/json package uses float64 for numbers by default, which is inaccurate for many web3 types, and unsupported here. The json.Decoder method UseNumber() will switch to using json.Number instead, which is accurate (full precision, backed by the original string) and supported here.
func ConvertInt ¶
ConvertInt converts a big.Int in to the provided type.
func FloatAsInt ¶
FloatAsInt converts a float to a *big.Int based on the decimals passed in
func IntAsFloat ¶
IntAsFloat converts a *big.Int (ie: wei), to *big.Float (ie: ETH)
func ParseAmount ¶
ParseAmount parses a string (human readable amount with units ie 1go, 1nanogo...) and returns big.Int value of this string in wei/atto
func ParseBigInt ¶
ParseBigInt parses a string (base 10 only) and returns big.Int value of this string in wei/atto
func ParseCombinedJSON ¶
func SendTransaction ¶
SendTransaction sends the Transaction
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
func CreateAccount ¶
func ParsePrivateKey ¶
func (*Account) Key ¶
func (a *Account) Key() *ecdsa.PrivateKey
func (*Account) PrivateKey ¶
type Block ¶
type Block struct { ParentHash common.Hash Sha3Uncles common.Hash Miner common.Address Signers []common.Address Voters []common.Address Signer []byte StateRoot common.Hash TxsRoot common.Hash ReceiptsRoot common.Hash LogsBloom *types.Bloom Difficulty *big.Int TotalDifficulty *big.Int Number *big.Int GasLimit uint64 GasUsed uint64 Timestamp time.Time ExtraData []byte MixHash common.Hash Nonce types.BlockNonce Hash common.Hash // Only one of TxHashes or TxDetails will be populated. TxHashes []common.Hash TxDetails []*Transaction Uncles []common.Hash }
func (*Block) ExtraVanity ¶
func (*Block) MarshalJSON ¶
func (*Block) UnmarshalJSON ¶
type CallMsg ¶
type CallMsg struct { From *common.Address // the sender of the 'transaction' To *common.Address // the destination contract (nil for contract creation) Gas uint64 // if 0, the call executes with near-infinite gas GasPrice *big.Int // wei <-> gas exchange ratio Value *big.Int // amount of wei sent along with the call Data []byte // input data, usually an ABI-encoded contract method invocation }
type Client ¶
type Client interface { // GetBalance returns the balance for an address at the given block number (nil for latest). GetBalance(ctx context.Context, address string, blockNumber *big.Int) (*big.Int, error) // GetCode returns the code for an address at the given block number (nil for latest). GetCode(ctx context.Context, address string, blockNumber *big.Int) ([]byte, error) // GetBlockByNumber returns block details by number (nil for latest), optionally including full txs. GetBlockByNumber(ctx context.Context, number *big.Int, includeTxs bool) (*Block, error) // GetBlockByHash returns block details for the given hash, optionally include full transaction details. GetBlockByHash(ctx context.Context, hash string, includeTxs bool) (*Block, error) // GetTransactionByHash returns transaction details for a hash. GetTransactionByHash(ctx context.Context, hash common.Hash) (*Transaction, error) // GetSnapshot returns the latest clique snapshot. GetSnapshot(ctx context.Context) (*Snapshot, error) // GetID returns unique identifying information for the network. GetID(ctx context.Context) (*ID, error) // GetTransactionReceipt returns the receipt for a transaction hash. GetTransactionReceipt(ctx context.Context, hash common.Hash) (*Receipt, error) // GetChainID returns the chain id for the network. GetChainID(ctx context.Context) (*big.Int, error) // GetNetworkID returns the network id. GetNetworkID(ctx context.Context) (*big.Int, error) // GetGasPrice returns a suggested gas price. GetGasPrice(ctx context.Context) (*big.Int, error) // GetPendingTransactionCount returns the transaction count including pending txs. // This value is also the next legal nonce. GetPendingTransactionCount(ctx context.Context, account common.Address) (uint64, error) // SendRawTransaction sends the signed raw transaction bytes. SendRawTransaction(ctx context.Context, tx []byte) error // Call executes a call without submitting a transaction. Call(ctx context.Context, msg CallMsg) ([]byte, error) Close() SetChainID(*big.Int) }
Client is an interface for the web3 RPC API.
type Contract ¶
type Contract struct { Code string `json:"code"` RuntimeCode string `json:"runtime-code"` Info ContractInfo `json:"info"` Hashes map[string]string `json:"hashes"` }
Contract contains information about a compiled contract, alongside its code and runtime code.
type ContractInfo ¶
type ContractInfo struct { Source string `json:"source"` Language string `json:"language"` LanguageVersion string `json:"languageVersion"` CompilerVersion string `json:"compilerVersion"` CompilerOptions string `json:"compilerOptions"` SrcMap interface{} `json:"srcMap"` SrcMapRuntime string `json:"srcMapRuntime"` AbiDefinition interface{} `json:"abiDefinition"` UserDoc interface{} `json:"userDoc"` DeveloperDoc interface{} `json:"developerDoc"` Metadata string `json:"metadata"` }
ContractInfo contains information about a compiled contract, including access to the ABI definition, source mapping, user and developer docs, and metadata.
Depending on the source, language version, compiler version, and compiler options will provide information about how the contract was compiled.
type Receipt ¶
type Receipt struct { PostState []byte Status uint64 CumulativeGasUsed uint64 Bloom types.Bloom Logs []*types.Log TxHash common.Hash TxIndex uint64 ContractAddress common.Address GasUsed uint64 ParsedLogs []Event BlockHash common.Hash BlockNumber uint64 From common.Address To *common.Address }
func WaitForReceipt ¶
WaitForReceipt polls for a transaction receipt until it is available, or ctx is cancelled.
func (*Receipt) MarshalJSON ¶
func (*Receipt) UnmarshalJSON ¶
type Solidity ¶
Solidity specifies the solidity compiler configuration.
func SolidityVersion ¶
SolidityVersion runs solc and parses its version output.
type Transaction ¶
type Transaction struct { Nonce uint64 GasPrice *big.Int // wei GasLimit uint64 To *common.Address Value *big.Int // wei Input []byte From common.Address V *big.Int R *big.Int S *big.Int Hash common.Hash BlockNumber *big.Int BlockHash common.Hash TransactionIndex uint64 }
func CallFunctionWithArgs ¶ added in v0.2.69
func CallFunctionWithArgs(ctx context.Context, client Client, privateKeyHex, address string, amount *big.Int, gasPrice *big.Int, gasLimit uint64, myabi abi.ABI, functionName string, params ...interface{}) (*Transaction, error)
CallFunctionWithArgs submits a transaction to execute a smart contract function call.
func CallFunctionWithData ¶ added in v0.2.69
func CallFunctionWithData(ctx context.Context, client Client, privateKeyHex, address string, amount *big.Int, gasPrice *big.Int, gasLimit uint64, data []byte) (*Transaction, error)
CallFunctionWithData if you already have the encoded function data, then use this
func CallTransactFunction ¶
func CallTransactFunction(ctx context.Context, client Client, myabi abi.ABI, address, privateKeyHex, functionName string, amount *big.Int, gasPrice *big.Int, gasLimit uint64, params ...interface{}) (*Transaction, error)
CallTransactFunction submits a transaction to execute a smart contract function call. @Deprecated use CallFunctionWithArgs, better signature
func DeployBin ¶
func DeployBin(ctx context.Context, client Client, privateKeyHex, binFilename, abiFilename string, gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*Transaction, error)
DeployBin will deploy a bin file to the network
func DeployContract ¶
func DeployContract(ctx context.Context, client Client, privateKeyHex string, binHex, abiJSON string, gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*Transaction, error)
DeployContract submits a contract creation transaction. abiJSON is only required when including params for the constructor.
func Send ¶
func Send(ctx context.Context, client Client, privateKeyHex string, address common.Address, amount *big.Int, gasPrice *big.Int, gasLimit uint64) (*Transaction, error)
Send performs a regular native coin transaction (not a contract)
func (*Transaction) MarshalJSON ¶
func (t *Transaction) MarshalJSON() ([]byte, error)
func (*Transaction) UnmarshalJSON ¶
func (t *Transaction) UnmarshalJSON(data []byte) error