Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Note that when using this class to decode transactions, logs, and return values, it does have one advantage over using the ProjectDecoder or ContractDecoder. If the artifact for the class does not have a deployedBytecode field, the ProjectDecoder (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, and will fall back to ABI mode when decoding return values received 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, or decode return values received from it in full mode, even if the deployedBytecode field is missing.

Hierarchy

  • ContractInstanceDecoder

Index

Constructors

Properties

additionalContexts: Contexts = {}
allocations: AllocationInfo
compilation: Compilation
compiler: CompilerVersion
contextHash: string
contexts: Contexts = {}
contract: Contract
contractAddress: string
contractCode: string
contractDecoder: ContractDecoder
contractNetwork: number
contractNode: AstNode
encoder: ProjectEncoder
internalFunctionsTable: InternalFunctions
mappingKeys: Slot[] = []
projectDecoder: ProjectDecoder
providerAdapter: ProviderAdapter
referenceDeclarations: {}

Type declaration

stateVariableReferences: StateVariableAllocation[]
storageCache: StorageCache = {}
userDefinedTypes: TypesById

Accessors

Methods

  • checkAllocationSuccess(): void
  • constructSlot(variable: string | number, ...indices: unknown[]): Promise<{ slot?: Slot; type?: Type }>
  • This method is asynchronous.

    This mostly behaves as ProjectDecoder.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

    • options: EventOptions = {}

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

    Returns Promise<DecodedLog[]>

  • getCode(address: string, block: RegularizedBlockSpecifier): Promise<Uint8Array>
  • getStorage(address: string, slot: BN, block: RegularizedBlockSpecifier): Promise<Uint8Array>
  • init(): Promise<void>
  • regularizeBlock(block: BlockSpecifier): Promise<RegularizedBlockSpecifier>
  • 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

    Returns Promise<ContractState>

  • unwatchMappingKey(variable: string | number, ...indices: unknown[]): 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.

    Parameters

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

    Returns Promise<void>

  • 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.

    • block: BlockSpecifier = "latest"

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

    Returns Promise<Result>

  • 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 a ContractAllocationFailedError.

    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

    Returns Promise<StateVariable[]>

  • watchMappingKey(variable: string | number, ...indices: unknown[]): 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.

    (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: string | number

      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: unknown[]

      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.

      Values (for array indices and mapping keys) may be given in any format understood by Truffle Encoder; see the documentation for [[Encoder.ProjectEncoder.wrap|ProjectEncoder.wrap]] for details.

      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