I made a dynamic array variable of address type, i.e.,
address payable[] public participant;
which one is the correct way to write in the following and why,
uint payable[] public participant;
or
uint[] payable public participant;
enter code here
There's address
and its extension address payable
, which allows you to use the native transfer()
method to send ETH to this address.
Since the type is called address payable
, you can make an array of this type by appending the []
expression after the type name.
There's no payable
extension to uint
. If your aim is to define an amount to be sent, that can be stored in a regular uint
.
pragma solidity ^0.8;
contract MyContract {
address payable[] public participants;
function foo() public {
uint amount = 1; // 1 wei
for (uint i = 0; i < participants.length; i++) {
participants[i].transfer(amount);
}
}
}