You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Packed encoding concatenates values without padding — shorter output, used for hashing.
69
+
Packed encoding concatenates values without padding — it's not self-describing (you must know the types to decode it). Used in Solidity's `abi.encodePacked()`for hashing and CREATE2 address computation.
@@ -138,7 +132,6 @@ MyParams result = abiEncode.DecodeEncodedComplexType<MyParams>(encodedBytes);
138
132
139
133
A function selector is the first 4 bytes of the Keccak-256 hash of the canonical function signature. It identifies which function to call in a contract.
@@ -416,6 +399,7 @@ For full EIP-712 signing workflows including verification and recovery, see the
416
399
## Next Steps
417
400
418
401
-[Smart Contract Interaction](../smart-contracts/guide-smart-contract-interaction) — use ABI encoding through typed contract handlers (recommended for most use cases)
402
+
-[Decode Transactions](guide-decode-transactions) — inspect and decode raw transaction calldata
419
403
-[EIP-712 Signing](../signing-and-key-management/guide-eip712-signing) — full typed data signing workflows
420
404
-[Events & Logs](../smart-contracts/guide-events) — decode event data from transaction receipts
421
405
-[Error Handling](../smart-contracts/guide-error-handling) — decode revert reasons and custom errors
Every Ethereum interaction starts with an address. When your application accepts an address from user input, reads one from a contract event, or compares addresses from different sources, you need to answer three questions: is it valid, is it the same address, and is it safely formatted?
11
+
12
+
Ethereum addresses are 20-byte hex strings, but they arrive in many forms: lowercase from RPC calls, uppercase from older wallets, mixed-case with an EIP-55 checksum, or truncated in sloppy data. `AddressUtil` in Nethereum handles all of these cases so you don't have to write your own comparison and validation logic.
EIP-55 is a mixed-case encoding that catches typos. The capitalisation of each hex letter is determined by hashing the address, so if you change any letter's case, the checksum fails. Always checksum addresses before displaying them to users or storing them.
Before processing any address from user input or external data, check that it is well-formed. This catches obvious mistakes early, before they cause a failed transaction or a confusing error deeper in your code.
Addresses from different sources often have different casing. An RPC node returns lowercase, a block explorer returns checksummed, and a user might paste uppercase. Direct string comparison would treat these as different addresses. Use case-insensitive comparison instead.
Smart contracts use the zero address (`0x0000...0000`) as a sentinel value, for example to indicate "no owner" or a burn destination. Null, empty strings, and short zero forms like `"0x0"` all represent the same concept. Detecting these prevents sending funds to an unrecoverable address.
When collecting addresses from events or transaction logs, duplicates with different casing are common. `UniqueAddressList` deduplicates automatically using case-insensitive comparison.
title: Decode Function Calls from Transaction Input
3
+
sidebar_label: "Decode Transactions"
4
+
sidebar_position: 12
5
+
description: Validate and decode smart contract function calls from transaction input data
6
+
---
7
+
8
+
# Decode Function Calls from Transaction Input
9
+
10
+
When you retrieve a transaction from the blockchain (as in [Query Blocks](guide-query-blocks)), its `Input` field contains the raw ABI-encoded function call. This guide shows how to check if a transaction calls a specific function and decode its parameters into typed C# objects.
11
+
12
+
```bash
13
+
dotnet add package Nethereum.Web3
14
+
dotnet add package Nethereum.Contracts
15
+
```
16
+
17
+
## Define the Function Message
18
+
19
+
The first 4 bytes of a transaction's input data identify which function is being called. This selector is the Keccak-256 hash of the function signature (e.g., `transfer(address,uint256)` produces `a9059cbb`). The remaining bytes are the ABI-encoded parameters.
20
+
21
+
To decode that data, define a C# class that mirrors the Solidity function signature. The `[Function]` and `[Parameter]` attributes tell Nethereum how to map the ABI-encoded bytes back to typed properties:
22
+
23
+
```csharp
24
+
usingNethereum.ABI.FunctionEncoding.Attributes;
25
+
usingNethereum.Contracts;
26
+
usingSystem.Numerics;
27
+
28
+
[Function("transfer", "bool")]
29
+
publicclassTransferFunction : FunctionMessage
30
+
{
31
+
[Parameter("address", "_to", 1)]
32
+
publicstringTo { get; set; }
33
+
34
+
[Parameter("uint256", "_value", 2)]
35
+
publicBigIntegerTokenAmount { get; set; }
36
+
}
37
+
```
38
+
39
+
## Check and Decode the Transaction
40
+
41
+
`IsTransactionForFunctionMessage<T>()` compares the first 4 bytes of the transaction input against the function selector derived from `TransferFunction`. If the selector matches, `DecodeTransaction` ABI-decodes the remaining bytes into the typed message. If the selector does not match, the transaction is for a different function and is skipped.
`Web3.Convert.FromWei` converts a raw `BigInteger` value in wei to its ether-unit decimal representation. See [Unit Conversion](guide-unit-conversion) for details.
62
+
63
+
## Next Steps
64
+
65
+
-[ABI Encoding](guide-abi-encoding) -- encode and decode smart contract data in depth
66
+
-[Query Blocks](guide-query-blocks) -- get block and transaction data
67
+
-[Transaction Recovery](guide-transaction-recovery) -- recover the sender from a signed transaction
0 commit comments