This function is asynchronous.
Constructs a contract encoder for a given contract artifact.
The artifact for the contract.
A contract constructor object may be substituted for the artifact, so if you're not sure which you're dealing with, it's OK.
The EncoderSettings to use; see the documentation for that type for more information. If absent, the encoder will be based on just the single contract provided; it is recommended to pass more information to get the encoder's full power.
Note that if the artifact contains unlinked libraries, you will have to
pass either the provider
or networkId
setting in order to encode
contract creation transactions.
This function is asynchronous.
Constructs a contract instance encoder for a deployed contract instance. You must pass in a provider or network ID to use this function.
The artifact corresponding to the type of the contract.
A contract constructor object may be substituted for the artifact, so if you're not sure which you're dealing with, it's OK.
The EncoderSettings to use, including the provider or network id; see the documentation for that type for more information.
This function is asynchronous.
Constructs a project encoder for the project.
This function is asynchronous.
Constructs a contract instance decoder for a contract instance at a given address.
The artifact corresponding to the type of the contract.
A contract constructor object may be substituted for the artifact, so if you're not sure which you're dealing with, it's OK.
The address of the contract instance to decode.
Address must either be checksummed, or in all one case to circumvent the checksum. Mixed-case with bad checksum will cause this function to throw an exception.
The EncoderSettings to use; see the documentation for that type for more information. If absent, the encoder will be based on just the single contract provided; it is recommended to pass more information to get the encoder's full power.
Note that if the artifact contains unlinked libraries, you will have to
pass either the provider
or networkId
setting in order to encode
contract creation transactions.
This function is asynchronous.
Constructs a contract encoder for a given contract.
The contract the encoder is for. It should have all of its libraries linked.
The EncoderSettings to use; see the documentation for that type for more information. If absent, the encoder will be based on just the single contract provided; it is recommended to pass more information to get the encoder's full power.
This function is asynchronous.
Constructs a contract instance encoder for a contract instance at a given address.
The contract constructor object corresponding to the type of the contract.
The address of the contract instance to decode.
Address must either be checksummed, or in all one case to circumvent the checksum. Mixed-case with bad checksum will cause this function to throw an exception.
The EncoderSettings to use; see the documentation for that type for more information. If absent, the encoder will be based on just the single contract provided; it is recommended to pass more information to get the encoder's full power.
This function is asynchronous.
Constructs a contract instance encoder for a deployed contract instance.
The contract abstraction object corresponding to the contract instance.
The EncoderSettings to use; see the documentation for that type for more information. If absent, the encoder will be based on just the single contract provided; it is recommended to pass more information to get the encoder's full power.
This function is asynchronous.
Constructs a contract instance encoder for a deployed contract instance.
The contract constructor object corresponding to the type of the contract.
The EncoderSettings to use; see the documentation for that type for more information. If absent, the encoder will be based on just the single contract provided; it is recommended to pass more information to get the encoder's full power.
Generated using TypeDoc
Truffle Encoder
This module provides an interface for recognizing JavaScript user input of Solidity values, encoding those values for use in a transaction, and performing overload resolution based on those values to determine which Solidity method to encode for.
The interface is split into three classes: The project encoder, the contract encoder, and the contract instance encoder. The project encoder is associated to the project as a whole; it can recognize user input, encode transactions, and resolve overloads, although the interface for the latter two is somewhat inconvenient. The contract encoder is associated to a specific contract class. It is similar to the project encoder, but presents an easier-to-use interface for transaction encoding and overload resolution, so long as one is dealing with methods of the specified class. The contract instance encoder is associated to a specific contract instance; it is like the contract encoder, but is associated to a specific address, allowing the
to
option in transactions to be populated automatically.Usage
Initialization
Create a encoder with one of the various constructor functions.
For a project encoder, use the
forProject
function.For a contract encoder, use the
forArtifact
orforContract
function.For a contract instance encoder, use one of the following:
forDeployedArtifact
forDeployedContract
forArtifactAt
forContractAt
forContractInstance
See the documentation of these functions for details, or below for usage examples.
All of these functions take a final argument in which information about the project is specified; currently only a few methods for specifying project information are allowed, but more are planned.
One can also spawn encoders from other encoders by supplying additional information. See the documentation for the individual encoder classes for a method listing.
Encoder methods
See the documentation for the individual encoder classes for a method listing.
Wrapped format information
When using the various "wrap" functions, values will be wrapped in machine-readable Format.Values.Value objects containing individual wrapped values. (This is the same format that
@truffle/decoder
produces output in.) See the format documentation for an overview and complete module listing.Use of project information and encoding of enums
The encoder can do purely ABI-based encoding, like other encoders; however it has the capability to use project information to do more.
The most significant use of this is that if further project information is present, this allows for enums to be entered as strings with the name of the option, rather than having to be entered via the underlying number. See the documentation of ProjectEncoder.wrap for more.
Similarly, if project information is present, the encoder will also throw an error if you attempt to put an out-of-range value into an enum type, and refuse to consider overloads that would result in this during overload resolution. If project information is absent, the encoder will be unable to recognize any error in these situations.
ENS resolution
The encoder supports ENS resolution for address and contract types if initialized to support such. See the documentation of the EncoderSettings and EnsSettings types for more.
Basic usage examples
These usage examples are for a project with two contracts,
Contract1
andContract2
. Let's suppose these look like the following:Encoding a transaction
Performing overload resolution