Web3 1.0 – Address Not Stored as Mixed-Case During Contract Creation

addressessoliditytruffleweb3js

I'm working with web3 1.0.0-beta.33, truffle-contract 3.0.5 and have noticed that when obtaining the list of accounts from my current web3 provider, addresses are in mixed-case as per the web3 1.0 documentation. When storing the msg.sender of my contract instantiation the address is stored as lower-case only.
When i call the mycontract.creator() it returns the correct account.
Tried doing it with and without metamask, truffle-contract, even switched between ganache-cli and my own geth node. Each time it has set the creator account as lower-case.
Here is the account list obtained from Firefox with metamask
accounts with metamask

here is the account list obtained from Chrome without metamask (provider is ganache-cli)
accounts without metamask
as you can see all account addresses are mixed-case, as expected in both cases, so I assume web3 is not the issue here.

The account comparison from the browser to the left is the one stored by my contract and the other one is obtained with web3.eth.getAccounts()[0]

firefox-metamask
accounts stored
chrome-ganache
obtained accounts from Chrome

These are the test results in which addresses are stored as expected
Test with ganache-cli
^ using ganache-cli

Test with geth node
^ using my own private network with geth nodes
Weird thing is that during my tests address stored by the contract are mixed-case

here is my contract code (the relevant parts)

pragma solidity ^0.4.18;

contract Ive {

address public creator;
address public owner;

constructor () public {
    creator = msg.sender;
    owner = msg.sender;
}

function setOwner(address _owner) external {
    owner = _owner;
    // allowVisitor(_owner);
    // emit OwnerAssigned(msg.sender, _owner);
}

}

Best Answer

Contracts don't store addresses in mixed case ever. That's because addresses are a hex representation of 20 bytes (and bytes don't have cases). The mixed case doesn't actually change the address at all, it is just a way of writing down the hex representation of an address that includes a checksum.

So whether a web3 call to a contract gives you back mixed case doesn't have anything to do with the contract, it has to do with the library you use to get the data from the contract. You can use web3.utils.toChecksumAddress to convert an address in upper/lower case to mixed case: https://web3js.readthedocs.io/en/1.0/web3-utils.html#tochecksumaddress

Also note that metamask uses web3 0.20.x which (afaik) doesn't use mixed case addresses by default, or is at least inconsistent.

Related Topic