docs/src/codec/decoding.md
Be sure to read the prerequisites to decoding.
Decoding is done via the ABIDecoder:
{{#include ../../../examples/codec/src/lib.rs:decoding_example}}
First into a Token, then via the Tokenizable trait, into the desired type.
If the type came from abigen! (or uses the ::fuels::macros::TryFrom derivation) then you can also use try_into to convert bytes into a type that implements both Parameterize and Tokenizable:
{{#include ../../../examples/codec/src/lib.rs:decoding_example_try_into}}
Under the hood, try_from_bytes is being called, which does what the preceding example did.
The decoder can be configured to limit its resource expenditure:
{{#include ../../../examples/codec/src/lib.rs:configuring_the_decoder}}
For an explanation of each configuration value visit the DecoderConfig.
The default values for the DecoderConfig are:
{{#include ../../../packages/fuels-core/src/codec/abi_decoder.rs:default_decoder_config}}
You can also configure the decoder used to decode the return value of the contract method:
{{#include ../../../examples/contracts/src/lib.rs:contract_decoder_config}}
The same method is available for script calls.