I have an smart contract with some defined fixed length variables from 3 to 5 characters long.
Defining these variables as string is more intuitive for those that come from another languages. Also creating unit tests is easier since I have just to pass the plain strings in the calls to the contract functions.
function deposit(string memory _name, uint256 _amount) internal { ... }
await contract.deposit('John', 10);
However, I read that, as I know these are 5-char fixed length variables we can also define them as bytes5 instead of strings. This makes tests more verbose because since you have to make the conversion string->bytes5 and bytes5->string on comparisons.
function deposit(bytes5 _name, uint256 _amount) internal { ... }
let stringToBytes5 = function (str: string) {
return ethers.utils.hexZeroPad(ethers.utils.toUtf8Bytes(str), 5);
}
let bytes5ToString = function (hexString: string) {
return ethers.utils.toUtf8String(hexString);
}
await contract.deposit(stringToBytes5('John'), 10);
So I would like to know if using bytes5 is really worth in terms of gas/performance/size... compared to using string.