Contract Address
Ethereum VM address is 20 bytes, but Vision's VM address is 21 bytes.
1. address conversion
Need to convert Vision's address while using in solidity (recommended):
/**
* @dev convert uint256 (HexString add 0x at beginning) vision address to solidity address type
* @param visionAddress uint256 visionAddress, begin with 0x, followed by HexString
* @return Solidity address type
*/
function convertFromVisionInt(uint256 visionAddress) public view returns(address){
return address(visionAddress);
}
This is similar with the grammar of the conversion from other types converted to address type in Ethereum.
2. address judgement
Solidity has address constant judgement, if using 21 bytes address the compiler will throw out an error, so you should use 20 bytes address, like:
function compareAddress(address visionAddress) public view returns (uint256){
// if (visionAddress == 0x46817ffa3d2f2028fcb9b8d2c619448cb3e3934c47) { // compile error
if (visionAddress == 0x817ffa3d2f2028fcb9b8d2c619448cb3e3934c47) { // right
return 1;
} else {
return 0;
}
}
But if you are using wallet-cli, you can use 21 bytes address, like 0000000000000000000046817ffa3d2f2028fcb9b8d2c619448cb3e3934c47
3. variable assignment
Solidity has address constant assignment, if using 21 bytes address the compiler will throw out an error, so you should use 20 bytes address, like:
function assignAddress() public view {
// address newAddress = 0x46817ffa3d2f2028fcb9b8d2c619448cb3e3934c47; // compile error
address newAddress = 0x817ffa3d2f2028fcb9b8d2c619448cb3e3934c47;
// do something
}
Updated almost 4 years ago