I created an array of structures and then tried to get the values of each account of an array. But I failed with an array while passing the address variable which contains msg.sender
and the type is not visibly convertible to uint256
. How can I do it?
Asked
Active
Viewed 1.3k times
9

Al Sweigart
- 11,566
- 10
- 64
- 92

Zera Abhraham
- 91
- 1
- 1
- 2
-
Welcome to SO! Please add some code, so we can see what you have tried so far. It's hard to tell where the Error may lies by now. – MiBrock Apr 10 '17 at 09:34
3 Answers
41
As of Solidity v0.8, you can no longer cast explicitly from address
to uint256
.
You can now use:
uint256 i = uint256(uint160(msg.sender));
function f(address a) internal pure returns (uint256) {
return uint256(uint160(a));
}

cfly24
- 1,882
- 3
- 22
- 56
5
You can cast it explicitly:
uint256 i = uint256(msg.sender);
function f(address a) constant returns (uint256) {
return uint256(a);
}

Zvezdomir Zlatinov
- 302
- 1
- 3
3
Pre v0.8.0 of Solidity you could do:
pragma <0.8.0;
return address(toUint(item));
Post v0.8.0 of Solidity you must now do:
pragma ^0.8.0
return address(uint160(toUint(item)));
- References
address(uint)
and uint(address)
: converting both type-category and width. Replace this by address(uint160(uint)
and uint(uint160(address))
respectively.

Sam Bacha
- 81
- 3