mapping(bytes32 => address) tokenSymboltoAddress;
1. The function saves tokenAddress on the tokenSymbol key in a mapping.
function addAddresses(bytes32 _name, address _tokenAddress ) {
tokenSymboltoAddress[bytes32] = _tokenAddress;
}
2. Returns the address added in the mapping on the given token symbol.
function getAddress(bytes32 name) returns (address) {
return tokenSymboltoAddress[name];
}
Can someone help me how to write or run these functions. How do we write symbol as bytes32 in function argument?
But what if users have to directly take input in bytes32. So first they have to convert string to bytes32. And then theh can input the data in bytes32.??
Emmm, the type of the function parameter is bytes32, so you should call this function with bytes32, as for user, they can pass a string, and you should convert it to the bytes32, or you can change the type in the contract, just use mapping(string => address) tokenSymboltoAddress;