0

splitter.sol

struct ERC20Payment {
  address token;
  uint256 amount;
}

I am curious why there is a loop for payout, which is declared as ERC20Payment[] calldata. I understand there are different tokens, and different addresses, is this why we use loop to identify different tokens?

1 Answer 1

1

Yes, the loop is iterating the variable payout i.e., an array of type ERC20Payment struct, and then accessing the corresponding fields named as token (of type address) and amount (of type uint256) iteratively.

Then, in each iteration, using the value of amount for calculating the respective feeAmount and calling the safeTransferFrom() function by instantiating the IERC20 interface using the value of token (i.e., the respective ERC20 token address).

2
  • But I am curious about how the iteration actually helps for identifying different tokens. For example address is 0F81S (160 bits)... and amount has 256 bits. So, there will be 416 bits in total for the ERC20Payments, which implies the length is 416. But, what payout[i] will stands for? Isn't it just a single character from address and the amount? Commented May 8 at 14:19
  • 1
    Actually, payout[i] means the single instance of ERC20Payment struct. It stores the token address and amount in the form of tuple, like [token,amount]. Commented May 8 at 14:28

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.