# Class ContractInstanceDecoder

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

- Defined in decoder/lib/decoders.ts:1603

#####
Index

### Constructors

constructor

### Properties

additionalContexts
allocations
compilation
compiler
contextHash
contexts
contract
contractAddress
contractCode
contractDecoder
contractNetwork
contractNode
encoder
internalFunctionsTable
mappingKeys
projectDecoder
providerAdapter
referenceDeclarations
stateVariableReferences
storageCache
userDefinedTypes

### Accessors

context

### Methods

abifyCalldataDecoding
abifyLogDecoding
abifyReturndataDecoding
checkAllocationSuccess
constructSlot
decodeLog
decodeReturnValue
decodeTransaction
decodeVariable
events
findVariableByNameOrId
getCode
getStorage
init
regularizeBlock
reverseEnsResolve
state
unwatchMappingKey
variable
variables
watchMappingKey

## Constructors

### `Protected` constructor

- new ContractInstanceDecoder(contractDecoder, address?): ContractInstanceDecoder
- `Protected`

  #### Parameters

  - ##### contractDecoder: ContractDecoder

  - ##### `Optional` address: string

  #### Returns ContractInstanceDecoder

  - Defined in decoder/lib/decoders.ts:1636

## Properties

### `Private` additionalContexts

additionalContexts: Contexts = {}

- Defined in decoder/lib/decoders.ts:1616

### `Private` allocations

allocations: AllocationInfo

- Defined in decoder/lib/decoders.ts:1620

### `Private` compilation

compilation: Compilation

- Defined in decoder/lib/decoders.ts:1606

### `Private` compiler

compiler: CompilerVersion

- Defined in decoder/lib/decoders.ts:1613

### `Private` contextHash

contextHash: string

- Defined in decoder/lib/decoders.ts:1612

### `Private` contexts

contexts: Contexts = {}

- Defined in decoder/lib/decoders.ts:1615

### `Private` contract

contract: Contract

- Defined in decoder/lib/decoders.ts:1607

### `Private` contractAddress

contractAddress: string

- Defined in decoder/lib/decoders.ts:1610

### `Private` contractCode

contractCode: string

- Defined in decoder/lib/decoders.ts:1611

### `Private` contractDecoder

contractDecoder: ContractDecoder

- Defined in decoder/lib/decoders.ts:1629

### `Private` contractNetwork

contractNetwork: number

- Defined in decoder/lib/decoders.ts:1609

### `Private` contractNode

contractNode: AstNode

- Defined in decoder/lib/decoders.ts:1608

### `Private` encoder

encoder: ProjectEncoder

- Defined in decoder/lib/decoders.ts:1631

### `Private` internalFunctionsTable

internalFunctionsTable: InternalFunctions

- Defined in decoder/lib/decoders.ts:1623

### `Private` mappingKeys

mappingKeys: Slot[] = []

- Defined in decoder/lib/decoders.ts:1625

### `Private` projectDecoder

projectDecoder: ProjectDecoder

- Defined in decoder/lib/decoders.ts:1630

### `Private` providerAdapter

providerAdapter: ProviderAdapter

- Defined in decoder/lib/decoders.ts:1604

### `Private` referenceDeclarations

referenceDeclarations: {
[compilationId: string]: AstNodes;
}

#### Type declaration

- ##### [compilationId: string]: AstNodes

- Defined in decoder/lib/decoders.ts:1618

### `Private` stateVariableReferences

stateVariableReferences: StateVariableAllocation[]

- Defined in decoder/lib/decoders.ts:1622

### `Private` storageCache

storageCache: StorageCache = {}

- Defined in decoder/lib/decoders.ts:1627

### `Private` userDefinedTypes

userDefinedTypes: TypesById

- Defined in decoder/lib/decoders.ts:1619

## Accessors

### `Private` context

- get context(): Context

- #### Returns Context

  - Defined in decoder/lib/decoders.ts:1778

## Methods

### abifyCalldataDecoding

- abifyCalldataDecoding(decoding): CalldataDecoding

- See [[ProjectDecoder.abifyCalldataDecoding]].

  #### Parameters

  - ##### decoding: CalldataDecoding

  #### Returns CalldataDecoding

  - Defined in decoder/lib/decoders.ts:2217

### abifyLogDecoding

- abifyLogDecoding(decoding): LogDecoding

- See [[ProjectDecoder.abifyLogDecoding]].

  #### Parameters

  - ##### decoding: LogDecoding

  #### Returns LogDecoding

  - Defined in decoder/lib/decoders.ts:2224

### abifyReturndataDecoding

- abifyReturndataDecoding(decoding): ReturndataDecoding

- See [[ProjectDecoder.abifyReturndataDecoding]].

  #### Parameters

  - ##### decoding: ReturndataDecoding

  #### Returns ReturndataDecoding

  - Defined in decoder/lib/decoders.ts:2231

### `Private` checkAllocationSuccess

- checkAllocationSuccess(): void

- #### Returns void

  - Defined in decoder/lib/decoders.ts:1782

### `Private` constructSlot

- constructSlot(variable, ...indices): Promise<{
  slot?: Slot;
  type?: Type;
  }>

- #### Parameters

  - ##### variable: string | number

  - ##### `Rest` ...indices: unknown[]

  #### Returns Promise<{
  slot?: Slot;
  type?: Type;
  }>

  - Defined in decoder/lib/decoders.ts:2265

### decodeLog

- decodeLog(log, options?): Promise<LogDecoding[]>

- This method is asynchronous.

  See [[ProjectDecoder.decodeLog]].

  #### Parameters

  - ##### log: Log

  - ##### options: DecodeLogOptions = {}

  #### Returns Promise<LogDecoding[]>

  - Defined in decoder/lib/decoders.ts:2181

### decodeReturnValue

- decodeReturnValue(abi, data, options?): Promise<ReturndataDecoding[]>

- This method is asynchronous.

  See [[ContractDecoder.decodeReturnValue]].

  If the contract artifact is missing its bytecode, using this method, rather than the one in [[ContractDecoder]], can sometimes provide additional decoding information.

  #### Parameters

  - ##### abi: FunctionEntry

  - ##### data: string

  - ##### options: ReturnOptions = {}

  #### Returns Promise<ReturndataDecoding[]>

  - Defined in decoder/lib/decoders.ts:2201

### decodeTransaction

- decodeTransaction(transaction): Promise<CalldataDecoding>

- This method is asynchronous.

  Behaves mostly as [[ProjectDecoder.decodeTransaction]]. However, it is capable of more robustly decoding transactions that were sent to this particular instance.

  #### Parameters

  - ##### transaction: Transaction

  #### Returns Promise<CalldataDecoding>

  - Defined in decoder/lib/decoders.ts:2166

### `Private` decodeVariable

- decodeVariable(variable, block): Promise<StateVariable>

- #### Parameters

  - ##### variable: StateVariableAllocation

  - ##### block: RegularizedBlockSpecifier

  #### Returns Promise<StateVariable>

  - Defined in decoder/lib/decoders.ts:1798

### events

- events(options?): Promise<DecodedLog[]>

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

  - Defined in decoder/lib/decoders.ts:2246

### `Private` findVariableByNameOrId

- findVariableByNameOrId(nameOrId): StateVariableAllocation

- #### Parameters

  - ##### nameOrId: string | number

  #### Returns StateVariableAllocation

  - Defined in decoder/lib/decoders.ts:1969

### `Private` getCode

- getCode(address, block): Promise<Uint8Array>

- #### Parameters

  - ##### address: string

  - ##### block: RegularizedBlockSpecifier

  #### Returns Promise<Uint8Array>

  - Defined in decoder/lib/decoders.ts:2035

### `Private` getStorage

- getStorage(address, slot, block): Promise<Uint8Array>

- #### Parameters

  - ##### address: string

  - ##### slot: BN

  - ##### block: RegularizedBlockSpecifier

  #### Returns Promise<Uint8Array>

  - Defined in decoder/lib/decoders.ts:2002

### `Protected` init

- init(): Promise<void>
- `Protected`

  #### Returns Promise<void>

  - Defined in decoder/lib/decoders.ts:1676

### `Private` regularizeBlock

- regularizeBlock(block): Promise<RegularizedBlockSpecifier>

- #### Parameters

  - ##### block: BlockSpecifier

  #### Returns Promise<RegularizedBlockSpecifier>

  - Defined in decoder/lib/decoders.ts:2046

### `Private` reverseEnsResolve

- reverseEnsResolve(address): Promise<Uint8Array>

- #### Parameters

  - ##### address: string

  #### Returns Promise<Uint8Array>

  - Defined in decoder/lib/decoders.ts:2042

### state

- state(block?): 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

  - ##### block: BlockSpecifier = "latest"

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

  #### Returns Promise<ContractState>

  - Defined in decoder/lib/decoders.ts:1871

### unwatchMappingKey

- unwatchMappingKey(variable, ...indices): 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>

  - Defined in decoder/lib/decoders.ts:2135

### variable

- variable(nameOrId, block?): Promise<Result>

- This method is asynchronous.

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

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

  #### 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>

  #### 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")`.

  - Defined in decoder/lib/decoders.ts:1951

### variables

- variables(block?): 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 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 [[Format.Values.FunctionInternalValue|FunctionInternalValue]] documentation and the README for more on how these are handled.

  #### Parameters

  - ##### block: BlockSpecifier = "latest"

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

  #### Returns Promise<StateVariable[]>

  - Defined in decoder/lib/decoders.ts:1911

### watchMappingKey

- watchMappingKey(variable, ...indices): 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|variables()]] and [[variable|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.)

  #### Parameters

  - ##### variable: string | number

    The variable that the mapping lives under; this works like the nameOrId argument to [[variable|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>

  #### 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")`.

  - Defined in decoder/lib/decoders.ts:2098

Generated using TypeDoc