[Ethereum] How to convert decode/encode string to Base58 encodingremixsolidity How to convert decode/encode string to Base58 on solidity? Best Answer I don't believe there's any built-in function for doing this, but here's a toBase58 implementation: https://github.com/MrChico/verifyIPFS/blob/master/contracts/verifyIPFS.sol#L28. Depending on your use case, it might be better to have Solidity deal with the raw bytes and convert to/from base58 outside of the contract (e.g. in JavaScript or whatever client language you're using). Related Solutionssolidity – How to Convert Address to String in Solidity Use abi.encodePacked(x) where x is the address. (Thanks @k06a) [Ethereum] How convert signed int256 into a string It is a good exercise to modify uint2str to handle signed input. function int2str(int i) internal pure returns (string){ if (i == 0) return "0"; bool negative = i < 0; uint j = uint(negative ? -i : i); uint l = j; // Keep an unsigned copy uint len; while (j != 0){ len++; j /= 10; } if (negative) ++len; // Make room for '-' sign bytes memory bstr = new bytes(len); uint k = len - 1; while (l != 0){ bstr[k--] = byte(48 + l % 10); l /= 10; } if (negative) { // Prepend '-' bstr[0] = '-'; } return string(bstr); } Related TopicTransaction Encoding – How to Encode Empty Transaction Fields in RLP
Best Answer
I don't believe there's any built-in function for doing this, but here's a
toBase58
implementation: https://github.com/MrChico/verifyIPFS/blob/master/contracts/verifyIPFS.sol#L28.Depending on your use case, it might be better to have Solidity deal with the raw bytes and convert to/from base58 outside of the contract (e.g. in JavaScript or whatever client language you're using).