0

I have a Smart Contract that receives transactions proposal, these proposals go through a voting period and when this period ends, the transaction can be executed if it has the necessary approving votes.

This is the code of my Smart Contract, for simplicity purposes I didn't include all the variables, functions, and events.

contract MultiSigWallet {
    struct Transaction {
        address to;
        uint value;
        bytes data;
        bool executed;
    }

    Transaction[] public transactions;
    mapping(uint => mapping(address => bool)) public approved;
    address[] public owners;

    function submit(address _to, uint _value, bytes calldata _data) 
        external
        onlyOwner
    {
        transactions.push(Transaction({
            to: _to,
            value: _value,
            data: _data,
            executed: false
        }));
        emit Submit(transactions.length - 1);
    }
}

My question is: After one of the owners submits a transaction proposal, how can the other owners know what is the function that it's going to be executed and with what parameters. I ask that because the only information about the function that is going to be executed is in the bytes _data received as an argument in the submit function, so the user would need to know what those bytes represent to be able to decide whether voting to approve or not the transaction.

1 Answer 1

0

Let's look an example:

As you can see this transaction has this calldata: 0xa71bbebe0000000000000000000000000000000000000000000000000000000000000002

If you calculate keccak256("mint(uint32)"), you'll get 0xa71bbebe, which is our function selector. So, the first 4 bytes show the target function. After function selection, we have 0000000000000000000000000000000000000000000000000000000000000002. EVM is a 256-bit stack machine. Every parameter has to be padded to 32-byte.

You can parse them in solidity or if you want to parse them on your client-side, you can use ethers.js or web3.js etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.