ABI – How to Troubleshoot abi.decode Errors When Decoding Structures

abidecoding

Function reverts when trying to decode this struct:

    struct NftProperties {
    uint32 dateOfFirstOperation;
    uint32 timestampStart;
    uint32 timestampEnd;
    int64 equivalentCO2;
    uint64 amountOfEnergy;
    uint64 amountOfEnergyInJ;
    address organizationUnitAddress;
    bytes12 organizationId;
    bytes12 assetId;
    bytes12 signalId;
    uint32 signalQuality;
    uint32 tokenTimestamp; 
    string energyUnit;
    string assetName;
    string meterName;
    string signalName;
}

Here is how I call the abi.decode:

    function getReferencedToken(uint tokenID, address contractAddress) public returns (NftProperties memory){
            
            (bool success, bytes memory returnData) =
            contractAddress.staticcall(abi.encodeWithSignature("getTokenProperties(uint256 tokenId)", tokenID));
        
            NftProperties memory returnValue = abi.decode(returnData,(NftProperties));
        
            require(success == true, "Success is not True");
        
            return returnValue;
        }

And this is the called encoded function that returns struct value:

function getTokenProperties(uint256 tokenId) public view returns (NftProperties memory nftProperties)  {
    require(
        tokenId >= 0 && tokenIdToNftProperties[tokenId].amountOfEnergy > 0,
        "Token and it's properties for with respective tokenId must exist!"
    );
    return tokenIdToNftProperties[tokenId];
}

NOTE: I double-checked the proper structure is imported/declared in all contracts that have to work with it.

However, I have no idea why the function reverts at abi.decode

Best Answer

Found the Mistake:

"getTokenProperties(uint256 tokenId)" 

should have been

"getTokenProperties(uint256)"