Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ContractInstanceDecoder

The ContractInstanceDecoder class. Decodes storage for a specified instance. Also, decodes transactions and logs. See below for a method listing.

Note that when using this class to decode transactions and logs, it does have one advantage over using the WireDecoder or ContractDecoder. If the artifact for the class does not have a deployedBytecode field, the WireDecoder (and therefore also the ContractDecoder) will not be able to tell that this instance is of that class, and so will fail to decode transactions sent to it or logs originating from it. However, the ContractInstanceDecoder has that information and will make use of it, making it possible for it to decode transactions sent to this instance, or logs originating from it, even if the deployedBytecode field is misssing.

Hierarchy

  • ContractInstanceDecoder

Index

Constructors

Protected constructor

Properties

Private additionalContexts

additionalContexts: DecoderContexts

Private allocations

allocations: AllocationInfo

Private contextHash

contextHash: string

Private contexts

contexts: DecoderContexts

Private contract

contract: ContractObject

Private contractAddress

contractAddress: string

Private contractCode

contractCode: string

Private contractDecoder

contractDecoder: ContractDecoder

Private contractNetwork

contractNetwork: string

Private contractNode

contractNode: AstNode

Private mappingKeys

mappingKeys: Slot[] = []

Private referenceDeclarations

referenceDeclarations: AstNodes

Private stateVariableReferences

stateVariableReferences: StorageMemberAllocation[]

Private storageCache

storageCache: StorageCache

Private userDefinedTypes

userDefinedTypes: TypesById

Private web3

web3: Web3

Private wireDecoder

wireDecoder: WireDecoder

Accessors

Private context

Methods

abifyCalldataDecoding

abifyLogDecoding

Private checkAllocationSuccess

  • checkAllocationSuccess(): void

Private constructSlot

  • constructSlot(variable: number | string, ...indices: any[]): [Slot | undefined, AstNode | undefined]

decodeLog

decodeTransaction

Private decodeVariable

events

  • This method is asynchronous.

    This mostly behaves as WireDecoder.events. However, unlike other variants of this function, this one, by default, restricts to events originating from this instance's address. If you don't want to restrict like that, you can explicitly use address: undefined in the options to disable this. (You can also of course set a different address to restrict to that.)

    Parameters

    • Default value options: EventOptions = {}

      Used to determine what events to fetch; see the documentation on the EventOptions type for more.

    Returns Promise<DecodedLog[]>

Private findVariableByNameOrId

Private getCode

  • getCode(address: string, block: DecoderTypes.RegularizedBlockSpecifier): Promise<Uint8Array>
  • Parameters

    • address: string
    • block: DecoderTypes.RegularizedBlockSpecifier

    Returns Promise<Uint8Array>

Private getStorage

  • getStorage(address: string, slot: BN, block: DecoderTypes.RegularizedBlockSpecifier): Promise<Uint8Array>
  • Parameters

    • address: string
    • slot: BN
    • block: DecoderTypes.RegularizedBlockSpecifier

    Returns Promise<Uint8Array>

Protected init

  • init(): Promise<void>

Private regularizeBlock

  • regularizeBlock(block: DecoderTypes.BlockSpecifier): Promise<DecoderTypes.RegularizedBlockSpecifier>
  • Parameters

    • block: DecoderTypes.BlockSpecifier

    Returns Promise<DecoderTypes.RegularizedBlockSpecifier>

state

  • state(block?: DecoderTypes.BlockSpecifier): Promise<ContractState>
  • This method is asynchronous.

    Returns information about the state of the contract, but does not include information about the storage or decoded variables. See the documentation for the ContractState type for more.

    Parameters

    • Default value block: DecoderTypes.BlockSpecifier = "latest"

      The block to inspect the contract's state at. Defaults to latest. See BlockSpecifier for legal values.

    Returns Promise<ContractState>

unwatchMappingKey

  • unwatchMappingKey(variable: number | string, ...indices: any[]): Promise<void>
  • This method is asynchronous.

    Opposite of watchMappingKey; unwatches the specified mapping key. See watchMappingKey for more on how watching mapping keys works, and on how the parameters work.

    Note that unwatching a mapping key will also unwatch all its descendants. E.g., if m is of type mapping(uint => mapping(uint => uint)), then unwatching m[0] will also unwatch m[0][0], m[0][1], etc, if these are currently watched.

    This function has the same caveats as watchMappingKey.

    Parameters

    • variable: number | string
    • Rest ...indices: any[]

    Returns Promise<void>

variable

  • variable(nameOrId: string | number, block?: DecoderTypes.BlockSpecifier): Promise<Result | undefined>
  • This method is asynchronous.

    Decodes an individual contract variable; returns its value as a Result. See the documentation for variables() for various caveats that also apply here.

    If the variable can't be located, throws an exception.

    example

    Consider a contract Derived inheriting from a contract Base. Suppose Derived has a variable x and Base has variables x and y. One can access Derived.x as variable("x") or variable("Derived.x"), can access Base.x as variable("Base.x"), and can access Base.y as variable("y") or variable("Base.y").

    Parameters

    • nameOrId: string | number

      The name (or numeric ID, if you know that) of the variable. Can be given as a qualified name, allowing one to get at shadowed variables from base contracts. If given by ID, can be given as a number or numeric string.

    • Default value block: DecoderTypes.BlockSpecifier = "latest"

      The block to inspect the contract's state at. Defaults to latest. See BlockSpecifier for legal values.

    Returns Promise<Result | undefined>

variables

  • variables(block?: DecoderTypes.BlockSpecifier): Promise<StateVariable[]>
  • This method is asynchronous.

    Decodes the contract's variables; returns an array of these decoded variables. See the documentation of the [[DecodedVariable]] type for more.

    Note that variable decoding can only operate in full mode; if the decoder wasn't able to start up in full mode, this method will throw an exception.

    Note that decoding mappings requires first watching mapping keys in order to get any results; see the documentation for watchMappingKey. Additional methods to make mapping decoding a less manual affair are planned for the future.

    Also, due to a technical limitation, it is not currently possible to usefully decode internal function pointers. See the FunctionInternalValue documentation and the README for more on how these are handled.

    Parameters

    • Default value block: DecoderTypes.BlockSpecifier = "latest"

      The block to inspect the contract's state at. Defaults to latest. See BlockSpecifier for legal values.

    Returns Promise<StateVariable[]>

watchMappingKey

  • watchMappingKey(variable: number | string, ...indices: any[]): Promise<void>
  • This method is asynchronous.

    Watches a mapping key; adds it to the decoder's list of watched mapping keys. This affects the results of both variables() and variable(). When a mapping is decoded, only the values at its watched keys will be included in its value.

    Note that it is possible to watch mappings that are inside structs, arrays, other mappings, etc; see below for more on how to do this.

    Note that watching mapping keys is only possible in full mode; if the decoder wasn't able to start up in full mode, this method will throw an exception.

    Warning: At the moment, this function does very little to check its input. Bad input may have unpredictable results. This will be remedied in the future (by having it throw exceptions on bad input), but right now essentially no checking is implemented. Also, there may be slight changes to the format of indices in the future.

    (A bad variable name will cause an exception though; that input is checked.)

    example

    First, a simple example. Say we have a mapping m of type mapping(uint => uint). You could call watchMappingKey("m", 0) to watch m[0].

    example

    Now for a slightly more complicated example. Say m is of type mapping(uint => mapping(uint => uint)), then to watch m[3][5], you can call watchMappingKey("m", 3, 5). This will also automatically watch m[3]; otherwise, watching m[3][5] wouldn't do much of anything.

    example

    Now for a well more complicated example. Say we have a struct type MapStruct with a member called map which is a mapping(string => string), and say we have a variable arr of type MapStruct[], then one could watch arr[3].map["hello"] by calling watchMappingKey("arr", 3, "map", "hello").

    Parameters

    • variable: number | string

      The variable that the mapping lives under; this works like the nameOrId argument to variable(). If the mapping is a top-level state variable, put the mapping itself here. Otherwise, put the top-level state variable it lives under.

    • Rest ...indices: any[]

      Further arguments to watchMappingKey, if given, will be interpreted as indices into or members of the variable identified by the variable argument; see the example. Array indices and mapping keys are specified by value; struct members are specified by name or (if you know it) numeric ID.

      Numeric values can be given as number, BN, or numeric string. Bytestring values are given as hex strings. Boolean values are given as booleans, or as the strings "true" or "false". Address values are given as hex strings; they are currently not required to be in checksum case, but this will likely change in the future, so don't rely on that.

      Note that if the path to a given mapping key includes mapping keys above it, any ancestors will also be watched automatically.

    Returns Promise<void>

Generated using TypeDoc