Address Reconstruction

In a Native collection, when a new Item is minted, the generated objectId value corresponds, after hexadecimal conversion, to the address of the ERC20 token created.

//The function to call in a Native EthItem Collection is 
//function mint(uint256 amount, string calldata tokenName, string calldata tokenSymbol, string calldata objectUri, bool editable) external returns(uint256 newObjectId, address interoperableInterfaceAddress);

//Let's suppose the call returns you the following values:

var objectId = "115229128895248074900976864697884278495202009447";
var interoperableInterfaceAddress = "0x142f0d872a9579c61098c783aed1c5f9404c6167"

//The HEX version of the objectId is EXACTLY the address of the created ERC20 Token

var builtAddress = web3.utils.toHex(objectId);

//-> will exactly return 0x142f0d872a9579c61098c783aed1c5f9404c6167, which is equal to the original interoperableInterfaceAddress value.

//Now let's retrieve back the objectId from the interoperableInterfaceAddress

//Convert in abi
var abiEncodedValue = web3.eth.abi.encodeParameter('address', interoperableInterfaceAddress);

//-> will generate the value "0x000000000000000000000000142f0d872a9579c61098c783aed1c5f9404c6167"

//Convert in uint256
var builtObjectId = web3.eth.abi.decodeParameter('uint256', abiEncodedValue);

//-> will exactly return "115229128895248074900976864697884278495202009447", which is equal to the original objectId value.                  

Last updated