4

So far I am using this solidity code

pragma solidity 0.4.24;

contract Converter{
    function Converter(){

    }

    function stringToBytes32(string memory source) returns (bytes32 result) {
        bytes memory tempEmptyStringTest = bytes(source);
        if (tempEmptyStringTest.length == 0) {
            return 0x0;
        }

        assembly {
            result := mload(add(source, 32))
        }
    }
}

Is there a website or online tool to easily convert strings to bytes32?

8

If you have MetaMask installed, then the following works in the browser console:

> web3.padRight(web3.fromAscii('hello'), 34)
"0x68656c6c6f0000000000000000000000"
1
  • This answer is no longer correct. From the official Metamask docs: For historical reasons, MetaMask injected web3@0.20.7 is deprecated. It has known security issues. It is no longer maintained by the web3.js team.
    – YulePale
    May 24 at 13:50
5

Online GUI here for converting bytes32 to string and the other way: https://blockchangers.github.io/solidity-converter-online/

0

Cindercloud also had an online converter, as well as some other useful tools for interacting with ethereum and other chains.

0

Another online GUI:

Convert from a bytes32/hex into a string/number or vice-versa.

https://web3-type-converter.onbrn.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.