Documentation ¶
Overview ¶
Package bind generates Ethereum contract Go bindings.
Detailed usage document and tutorial available on the go-ethereum Wiki page: https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts
Index ¶
- Variables
- func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]string, ...) (string, error)
- func CreateAddress(b cfxaddress.Address, nonce uint64, initBytecode []byte) cfxaddress.Address
- type BoundContract
- func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method string, params ...interface{}) error
- func (c *BoundContract) DecodeOutput(results *[]interface{}, output []byte, method string) error
- func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]interface{}) (chan types.Log, error)
- func (c *BoundContract) GenRequest(opts *CallOpts, method string, params ...interface{}) types.CallRequest
- func (c *BoundContract) GenUnsignedTransaction(opts *TransactOpts, method string, params ...interface{}) types.UnsignedTransaction
- func (c *BoundContract) RawTransact(opts *TransactOpts, calldata []byte) (*types.UnsignedTransaction, *types.Hash, error)
- func (c *BoundContract) Transact(opts *TransactOpts, method string, params ...interface{}) (*types.UnsignedTransaction, *types.Hash, error)
- func (c *BoundContract) Transfer(opts *TransactOpts) (*types.UnsignedTransaction, *types.Hash, error)
- func (c *BoundContract) UnpackLog(out interface{}, event string, log types.Log) error
- func (c *BoundContract) UnpackLogIntoMap(out map[string]interface{}, event string, log types.Log) error
- func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]interface{}) (chan types.SubscriptionLog, event.Subscription, error)
- type CallOpts
- type ContractBackend
- type ContractCaller
- type ContractFilterer
- type ContractTransactor
- type DeployBackend
- type FilterOpts
- type Lang
- type SignerFn
- type TransactOpts
- type WatchOpts
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoCode is returned by call and transact operations for which the requested // recipient contract to operate on does not exist in the state db or does not // have any code associated with it (i.e. suicided). ErrNoCode = errors.New("no contract code at given address") // This error is raised when attempting to perform a pending state action // on a backend that doesn't implement PendingContractCaller. ErrNoPendingState = errors.New("backend does not support pending state") )
Functions ¶
func Bind ¶
func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]string, pkg string, lang Lang, libs map[string]string, aliases map[string]string) (string, error)
Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant to be used as is in client code, but rather as an intermediate struct which enforces compile time type safety and naming convention opposed to having to manually maintain hard coded strings that break on runtime.
func CreateAddress ¶
func CreateAddress(b cfxaddress.Address, nonce uint64, initBytecode []byte) cfxaddress.Address
CreateAddress creates an ethereum address given the bytes and the nonce
Types ¶
type BoundContract ¶
type BoundContract struct {
// contains filtered or unexported fields
}
BoundContract is the base wrapper object that reflects a contract on the Ethereum network. It contains a collection of methods that are used by the higher level contract bindings to operate.
func DeployContract ¶
func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend ContractBackend, params ...interface{}) (*types.UnsignedTransaction, *types.Hash, *BoundContract, error)
DeployContract deploys a contract onto the Ethereum blockchain and binds the deployment address with a Go wrapper.
func NewBoundContract ¶
func NewBoundContract(address types.Address, abi abi.ABI, caller ContractCaller, transactor ContractTransactor, filterer ContractFilterer) *BoundContract
NewBoundContract creates a low level contract interface through which calls and transactions may be made through.
func (*BoundContract) Call ¶
func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method string, params ...interface{}) error
Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.
func (*BoundContract) DecodeOutput ¶
func (c *BoundContract) DecodeOutput(results *[]interface{}, output []byte, method string) error
func (*BoundContract) FilterLogs ¶
func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]interface{}) (chan types.Log, error)
FilterLogs filters contract logs for past blocks, returning the necessary channels to construct a strongly typed bound iterator on top of them.
func (*BoundContract) GenRequest ¶
func (c *BoundContract) GenRequest(opts *CallOpts, method string, params ...interface{}) types.CallRequest
func (*BoundContract) GenUnsignedTransaction ¶
func (c *BoundContract) GenUnsignedTransaction(opts *TransactOpts, method string, params ...interface{}) types.UnsignedTransaction
func (*BoundContract) RawTransact ¶
func (c *BoundContract) RawTransact(opts *TransactOpts, calldata []byte) (*types.UnsignedTransaction, *types.Hash, error)
RawTransact initiates a transaction with the given raw calldata as the input. It's usually used to initiate transactions for invoking **Fallback** function.
func (*BoundContract) Transact ¶
func (c *BoundContract) Transact(opts *TransactOpts, method string, params ...interface{}) (*types.UnsignedTransaction, *types.Hash, error)
Transact invokes the (paid) contract method with params as input values.
func (*BoundContract) Transfer ¶
func (c *BoundContract) Transfer(opts *TransactOpts) (*types.UnsignedTransaction, *types.Hash, error)
Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.
func (*BoundContract) UnpackLog ¶
func (c *BoundContract) UnpackLog(out interface{}, event string, log types.Log) error
UnpackLog unpacks a retrieved log into the provided output structure.
func (*BoundContract) UnpackLogIntoMap ¶
func (c *BoundContract) UnpackLogIntoMap(out map[string]interface{}, event string, log types.Log) error
UnpackLogIntoMap unpacks a retrieved log into the provided map.
func (*BoundContract) WatchLogs ¶
func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]interface{}) (chan types.SubscriptionLog, event.Subscription, error)
WatchLogs filters subscribes to contract logs for future blocks, returning a subscription object that can be used to tear down the watcher.
type CallOpts ¶
type CallOpts struct { Pending bool // Whether to operate on the pending state or the last known one From *types.Address // Optional the sender address, otherwise the first account is used EpochNumber *types.Epoch // Optional the block number on which the call should be performed Context context.Context // Network context to support cancellation and timeouts (nil = no timeout) }
CallOpts is the collection of options to fine tune a contract call request.
type ContractBackend ¶
type ContractBackend interface { ContractCaller ContractTransactor ContractFilterer }
ContractBackend defines the methods needed to work with contracts on a read-write basis.
type ContractCaller ¶
type ContractCaller interface { // CodeAt returns the code of the given account. This is needed to differentiate // between contract internal errors and the local chain being out of sync. GetCode(address types.Address, epoch ...*types.EpochOrBlockHash) (hexutil.Bytes, error) // ContractCall executes an Ethereum contract call with the specified data as the // input. Call(request types.CallRequest, epoch *types.EpochOrBlockHash) (hexutil.Bytes, error) }
ContractCaller defines the methods needed to allow operating with a contract on a read only basis.
type ContractFilterer ¶
type ContractFilterer interface { // FilterLogs executes a log filter operation, blocking during execution and // returning all the results in one batch. GetLogs(filter types.LogFilter) (logs []types.Log, err error) // SubscribeLogs creates a background log filtering operation, returning // a subscription immediately, which can be used to stream the found events. SubscribeLogs(channel chan types.SubscriptionLog, filter types.LogFilter) (*rpc.ClientSubscription, error) }
ContractFilterer defines the methods needed to access log events using one-off queries or continuous event subscriptions.
type ContractTransactor ¶
type ContractTransactor interface { // EstimateGasAndCollateral tries to estimate the gas and storage collateral // needed to execute a specific transaction based on the current pending state // of the backend blockchain. There is no guarantee that this is the true gas // limit requirement as other transactions may be added or removed by miners, // but it should provide a basis for setting a reasonable default. EstimateGasAndCollateral(request types.CallRequest, epoch ...*types.Epoch) (estimat types.Estimate, err error) // SendTransaction injects the transaction into the pending pool for execution. SendTransaction(tx types.UnsignedTransaction) (types.Hash, error) ApplyUnsignedTransactionDefault(tx *types.UnsignedTransaction) error }
ContractTransactor defines the methods needed to allow operating with a contract on a write only basis. Besides the transacting method, the remainder are helpers used when the user does not provide some needed values, but rather leaves it up to the transactor to decide.
type DeployBackend ¶
type DeployBackend interface { TransactionReceipt(txHash common.Hash) (*types.TransactionReceipt, error) GetCode(address types.Address, epoch ...*types.EpochOrBlockHash) (hexutil.Bytes, error) }
DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
type FilterOpts ¶
type FilterOpts struct { Start *types.Epoch // Start of the queried range End *types.Epoch // End of the range (nil = latest) }
FilterOpts is the collection of options to fine tune filtering for events within a bound contract.
type SignerFn ¶
type SignerFn func(common.Address, *types.UnsignedTransaction) (*types.UnsignedTransaction, error)
SignerFn is a signer function callback when a contract requires a method to sign the transaction before submission.
type TransactOpts ¶
type TransactOpts = types.ContractMethodSendOption