Decode parameter data sent to onERC721Received

Sending encoded parameter data along to an onERC721Received implementation function and actually decoding back the data

:computer: Environment
$ npx truffle version
Truffle v5.2.6 (core: 5.2.6)
Solidity - 0.8.0 (solc-js)
Node v10.19.0
Web3.js v1.2.9

:memo:Details
Hi , so im trying to send some parameters along with an nft to an aution contract. Ive used thte safeTransferFrom to onERC721Received were I cant seem to decode the data back into something useful (e.g. struct AuctionParameters{}) .

Question 1:
Am I encoding the parameters correctly , or is there a better way ?
abi.encodePacked(
uint128(_price),
uint(_biddingTime)
)

Question 2
how do I get to decode this data back to a struct or its loose properties ?
(uint128 _price, uint _biddingTime) = abi.decode(data, (uint128,uint));
doesnt seem to work

Thanks in advance

:1234: Code to reproduce
`pragma solidity ^0.8.0;

contract ERC721PresetMinterPauserAutoIdUpgradeable {

// function used to send tokens to get auctioned
function auctionNFT(address _to, uint256 _tokenId, uint128 _price, uint _biddingTime) public {
    ERC721Upgradeable.safeTransferFrom(
        msg.sender,
        _to,
        _tokenId,
        abi.encodePacked(
            uint128(_price),
            uint(_biddingTime)
        )
    );
}

}
contract AuctionContract {

// Deposit an asset and start an auction
function onERC721Received(
    address,
    address from,
    uint256 _tokenId,
    bytes calldata data
) external returns (bytes4)
{
    // TODO - fix decode data send with calldata
     (uint128 _price, uint _biddingTime) = abi.decode(data, (uint128,uint));

    Auction memory _auction = Auction({
        beneficiaryAddress : from,
        price : uint128(_price),
        auctionClose : (block.timestamp + _biddingTime),
        topBidder : address(0),
        topBid : 0,
        data : data,
        auctionComplete : false
        });

    tokenIdToAuction[_tokenId] = _auction;

    return this.onERC721Received.selector;
}

struct AuctionParameters {
    uint128 price;
    uint auctionClose;
}

struct Auction {
    // Action parameters
    address beneficiaryAddress;
    uint128 price;
    uint auctionClose;

    // Current state of the auction.
    address topBidder;
    uint topBid;

    // Will be set true once the auction is complete, preventing any further change
    bool auctionComplete;
    bytes data;
}

mapping(uint256 => Auction) public tokenIdToAuction;

}
`

the decode
(uint128 _price, uint _biddingTime) = abi.decode(data, (uint128,uint));
ended up working, its was my IDE that was trowing me off

2 Likes