AbstractContract
in package
AbstractContract serves as the base class for all Ethereum smart contract bindings.
It handles various tasks such as transaction management and encoding/decoding of ABI parameters of underlying contract binding.
Tags
Table of Contents
Properties
- $noSend : bool
- $transactionFeesPercentageBump : int
- $contractAddress : Address
- $fallbackFrom : Address|null
- $key : Key|null
- $rpc : AbstractRPC
Methods
- __construct() : mixed
- Constructs a new instance of the underlying binding. This assumes the contract is deployed. If it's not the case, deploy it using static functions.
- abi() : string
- Returns raw ABI JSON string, as is during abigen run.
- bytecode() : string|null
- Returns raw bytecode hex string, as is during abigen run. Used for deployment.
- getContractAddress() : Address
- Gets the contract address this object is bound to.
- getEventsFromReceipt() : array<string|int, AbstractEvent>
- Parses all logs from the receipt and returns them in array, in order of events in receipt. All possible transaction types are listed as class-strings in static::getEventsRegistry()
- loadPrivK() : static
- Loads a private key into the object for signing transactions. Calls will be done using address that comes from this key, and fallback address will be not used.
- setFallbackFrom() : static
- Sets a fallback address. See constructor documentation for details.
- unloadPrivK() : static
- Removes the private key from the object, making it no longer sign transactions, and fallback address will be used for estimations, if set, otherwise NULL address will be used.
- unsetFallbackFrom() : static
- Sets the fallback address to null. See constructor documentation for details.
- expectBinarySizeNormalizeString() : string
- expectIntArrOfSize() : array<string|int, mixed>
- expectIntOfSize() : OOGmp
- getEventsRegistry() : array<string|int, mixed>
- mkCall() : string
- mkPayableTxn() : Transaction
- mkTxn() : Transaction
- parseOutput() : mixed
- runNonPayableDeploy() : Transaction
- Executes a non-payable smart contract deploy.
- runPayableDeploy() : Transaction
- _mkTxn() : Transaction
- getDeployTransaction() : Transaction
- getFromAddress() : Address
Properties
$noSend
public
bool
$noSend
= false
is to be directly set from outside. If set to true, transactions will be created but not sent. Useful for gas estimations to be presented to user, or inspecting transaction before sending it.
$transactionFeesPercentageBump
public
static int
$transactionFeesPercentageBump
= 0
is to be directly set from outside. It increases gas price by this amount of percent. If set to 0, the bare minimum fees will be applied. If set to negative, probably insufficient fees will be set, but still there is possibility of transaction to go through. If set to for example 20, the fees will be 120% of what is estimated to be bare minimum
$contractAddress
protected
Address
$contractAddress
$fallbackFrom
protected
Address|null
$fallbackFrom
= null
$key
protected
Key|null
$key
= null
Attributes
- #[SensitiveParameter]
$rpc
protected
AbstractRPC
$rpc
Methods
__construct()
Constructs a new instance of the underlying binding. This assumes the contract is deployed. If it's not the case, deploy it using static functions.
public
__construct(AbstractRPC $rpc, Address $contractAddress[, Key|null $key = null ][, Address|null $fallbackFrom = null ]) : mixed
Parameters
- $rpc : AbstractRPC
-
The RPC interface used for interacting with Ethereum.
- $contractAddress : Address
-
The address of the deployed smart contract.
- $key : Key|null = null
-
Optional, nullable private key for signing transactions. Without it transactions will be returned unsigned and unsent, and calls/estimations will be with from field $fallbackFrom.
- $fallbackFrom : Address|null = null
-
Optional, nullable address to be used if the private key is not available for calls from field and gas estimations. If this field is null, Address::NULL() will be used. If you intend to sign the transaction, it's good idea to set this field to address of private key, since contracts may use msg.sender which may change if transaction reverts, or change which branches get executing resulting in bogus gas estimations. Note, that reverts throw exceptions.
abi()
Returns raw ABI JSON string, as is during abigen run.
public
abstract static abi() : string
Return values
stringbytecode()
Returns raw bytecode hex string, as is during abigen run. Used for deployment.
public
abstract static bytecode() : string|null
Since bytecode is optional, the return is nullable, and when it is null, the deploy methods aren't generated.
Return values
string|nullgetContractAddress()
Gets the contract address this object is bound to.
public
getContractAddress() : Address
Return values
Address —Address of the contract.
getEventsFromReceipt()
Parses all logs from the receipt and returns them in array, in order of events in receipt. All possible transaction types are listed as class-strings in static::getEventsRegistry()
public
static getEventsFromReceipt(Receipt $rcpt) : array<string|int, AbstractEvent>
Parameters
- $rcpt : Receipt
-
The transaction receipt.
Tags
Return values
array<string|int, AbstractEvent> —Array of parsed events.
loadPrivK()
Loads a private key into the object for signing transactions. Calls will be done using address that comes from this key, and fallback address will be not used.
public
loadPrivK(Key $key) : static
Parameters
- $key : Key
-
The private key.
Return values
static —The same object instance.
setFallbackFrom()
Sets a fallback address. See constructor documentation for details.
public
setFallbackFrom(Address $addr) : static
Parameters
- $addr : Address
-
The address to set.
Return values
static —The same object instance.
unloadPrivK()
Removes the private key from the object, making it no longer sign transactions, and fallback address will be used for estimations, if set, otherwise NULL address will be used.
public
unloadPrivK() : static
Return values
static —The same object instance.
unsetFallbackFrom()
Sets the fallback address to null. See constructor documentation for details.
public
unsetFallbackFrom() : static
Return values
static —The same object instance.
expectBinarySizeNormalizeString()
protected
static expectBinarySizeNormalizeString(string $binOrHex, int $length) : string
Parameters
- $binOrHex : string
- $length : int
Tags
Return values
stringexpectIntArrOfSize()
protected
static expectIntArrOfSize(bool $unsigned, array<string|int, mixed> $value, int $bits) : array<string|int, mixed>
Parameters
- $unsigned : bool
- $value : array<string|int, mixed>
- $bits : int
Tags
Return values
array<string|int, mixed>expectIntOfSize()
protected
static expectIntOfSize(bool $unsigned, int|OOGmp $value, int $bits) : OOGmp
Parameters
- $unsigned : bool
- $value : int|OOGmp
- $bits : int
Tags
Return values
OOGmpgetEventsRegistry()
protected
abstract static getEventsRegistry() : array<string|int, mixed>
Return values
array<string|int, mixed>mkCall()
protected
mkCall(string $signature[, array<string|int, mixed> $params = [] ]) : string
Parameters
- $signature : string
- $params : array<string|int, mixed> = []
Tags
Return values
stringmkPayableTxn()
protected
mkPayableTxn(string $signature, OOGmp $value, array<string|int, mixed> $params) : Transaction
Parameters
- $signature : string
- $value : OOGmp
- $params : array<string|int, mixed>
Tags
Return values
TransactionmkTxn()
protected
mkTxn(string $signature[, array<string|int, mixed> $params = [] ]) : Transaction
Parameters
- $signature : string
- $params : array<string|int, mixed> = []
Tags
Return values
TransactionparseOutput()
protected
parseOutput(string $output, string $type[, array<string|int, mixed>|null $tupleReplacements = null ]) : mixed
Parameters
- $output : string
- $type : string
- $tupleReplacements : array<string|int, mixed>|null = null
Tags
runNonPayableDeploy()
Executes a non-payable smart contract deploy.
protected
static runNonPayableDeploy(string $constructorParamsSig, Key $pk, AbstractRPC $rpc[, array<string|int, mixed> $params = [] ]) : Transaction
Parameters
- $constructorParamsSig : string
-
ABI constructor signature.
- $pk : Key
-
Private key for signing.
- $rpc : AbstractRPC
-
RPC interface for Ethereum.
- $params : array<string|int, mixed> = []
-
ABI encoded constructor params.
Tags
Return values
Transaction —The resulting transaction.
runPayableDeploy()
protected
static runPayableDeploy(string $constructorParamsSig, Key $pk, AbstractRPC $rpc, OOGmp $value[, array<string|int, mixed> $params = [] ]) : Transaction
Parameters
- $constructorParamsSig : string
- $pk : Key
- $rpc : AbstractRPC
- $value : OOGmp
- $params : array<string|int, mixed> = []
Tags
Return values
Transaction_mkTxn()
private
_mkTxn(string $signature, array<string|int, mixed> $params, bool $careAboutEstims[, bool $trimmedSignature = false ][, OOGmp|null $value = null ]) : Transaction
Parameters
- $signature : string
- $params : array<string|int, mixed>
- $careAboutEstims : bool
- $trimmedSignature : bool = false
- $value : OOGmp|null = null
Tags
Return values
TransactiongetDeployTransaction()
private
static getDeployTransaction(string $constructorParamsSig, Key $pk, AbstractRPC $rpc, array<string|int, mixed> $params, OOGmp|null $value) : Transaction
Parameters
- $constructorParamsSig : string
- $pk : Key
- $rpc : AbstractRPC
- $params : array<string|int, mixed>
- $value : OOGmp|null
Tags
Return values
TransactiongetFromAddress()
private
getFromAddress() : Address