I am looking for an option to efficiently convert a string passed to a function as a parameter, interpreted as hex, into bytes
. In Solidity.
I.e. doing the same that this piece of code would do
bytes memory b = hex"abcdef1234567890";
just with a string passed as a parameter for a function.
contract C {
function f(string memory s) public pure returns (bytes memory) {
bytes memory b;
... // read hex-string into b
return b;
}
}
Ideally, I'd want something that isn't "manually" looping through the characters of the string in order to translate each into a byte individually as described here: Solidity convert hex string to bytes. Unfortunately, I can't do this off-chain.
Is there such a way?