According to the documentation on the Solidity ABI:
address: equivalent to uint160, except for the assumed interpretation and language typing
The Solidity documentation carries on to say:
address: Holds a 20 byte value (size of an Ethereum address). Address types also have members and serve as a base for all contracts.
You should note firstly that the address type serves as a base for all contracts, in fact contracts inherit some members and functions from the address type. As such, when one initializes an address variable, it is possible to query the account at said address in the following ways, as stated in the documentation (here & here).
<address>.balance (uint256): balance of the Address in Wei
<address>.transfer(uint256 amount): send given amount of Wei to Address, throws on failure
<address>.send(uint256 amount) returns (bool): send given amount of Wei to Address, returns false on failure
<address>.call(...) returns (bool): issue low-level CALL, returns false on failure
<address>.callcode(...) returns (bool): issue low-level CALLCODE, returns false on failure
<address>.delegatecall(...) returns (bool): issue low-level DELEGATECALL, returns false on failure
The advantage of using an address variable instead of a uint160 is therefore the advantage it gives when querying or interacting with accounts (externally owned or contract accounts).
Using the address type also serves to improve readability, in that it tells the reader of the contract that the value stored relates to a contract address.
NOTE: As of version 5.0.0 of Solidity, members of the address type will no longer be available to contract types - you will need to explicitly cast to the address type first in order to use them.
Answer from Harry Wright on Stack ExchangeAccording to the documentation on the Solidity ABI:
address: equivalent to uint160, except for the assumed interpretation and language typing
The Solidity documentation carries on to say:
address: Holds a 20 byte value (size of an Ethereum address). Address types also have members and serve as a base for all contracts.
You should note firstly that the address type serves as a base for all contracts, in fact contracts inherit some members and functions from the address type. As such, when one initializes an address variable, it is possible to query the account at said address in the following ways, as stated in the documentation (here & here).
<address>.balance (uint256): balance of the Address in Wei
<address>.transfer(uint256 amount): send given amount of Wei to Address, throws on failure
<address>.send(uint256 amount) returns (bool): send given amount of Wei to Address, returns false on failure
<address>.call(...) returns (bool): issue low-level CALL, returns false on failure
<address>.callcode(...) returns (bool): issue low-level CALLCODE, returns false on failure
<address>.delegatecall(...) returns (bool): issue low-level DELEGATECALL, returns false on failure
The advantage of using an address variable instead of a uint160 is therefore the advantage it gives when querying or interacting with accounts (externally owned or contract accounts).
Using the address type also serves to improve readability, in that it tells the reader of the contract that the value stored relates to a contract address.
NOTE: As of version 5.0.0 of Solidity, members of the address type will no longer be available to contract types - you will need to explicitly cast to the address type first in order to use them.
I would suggest to have a look at the documentation of Solidity:
Meaning of type address
Address related methods which you can call
According to provided links, you can see that using address datatype provides you most important functionality of the address that you should have.
solidity - What is address[]? - Ethereum Stack Exchange
What is the maximum size of user data a smart contract can hold?
Passing encrypted messages via smart contracts.
The answer is "yes" in a technical sense. Although you wouldn't want to put the encryption part on chain because your plaintext would be visible publicly. You could implement ECIES decryption on chain but it might be difficult (impossible?) to implement inside of the gas limit. Even then, you'd have to pull out the private key and pass it to the contract. You're much better off just storing encrypted data on chain and decrypt it with a client utility like parity_decryptMessage.
More on reddit.comIs it possible to clear a mapping?
address[] is a type, an array of addresses. You can think of it as a list of addresses.
The square brackets, [], are use to specify that this type is an array.
You can create an array of many things, like an array of uint256 numbers:
uint256[] numbers;
And many more with a similar syntax.
Many languages use the [] to create or declare an array. Like Javascript: const numbers = [];. We can usually initiate an array with values, like in js: const numbers = [1,2,3,4,5];. In Solidity it would look like this for an array of uint256 numbers in storage: uint256[] numbers = [1,2,3,4];
In your case, an array of addresses can be declared as a state variable as follows:
address[] admins;
And then, in another function you can add addresses to that array:
function addAdmin(address adminAddress) public onlyOwner {
admins.push(adminAddress);
}
Of if you know the address before hand you can hard code them while you declare the array of addresses, like this:
address[] admins = [0x66B0b1d2930059407DcC30F1A2305435fc37315E, 0x6827b8f6cc60497d9bf5210d602C0EcaFDF7C405];
Arrays are really useful to hold a collection of things, objects, numbers, addresses, strings, etc.
We access arrays by index, starting at index 0 for the first element in most programming languages. If I want to access the first element of the array, then I do:
admins[0];
For the second:
admins[1];
And so on. Or in a loop:
for(uint256 i = 0; i < admins.length; i++) {
address adminAddress = admins[i];
// ...
// do something with adminAddress
}
And so on.
Solidity has many rules for arrays. State and local arrays are usually declared differently and used a bit differently in some cases. To learn more about them you can check the documentation: https://docs.soliditylang.org/en/latest/types.html#arrays
I hope it has helped.
In Solidity, address[] is an array consisting of addresses.
See: How can I instantiate an array of addresses?