0

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?

6

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

> web3.padRight(web3.fromAscii('hello'), 34)
"0x68656c6c6f0000000000000000000000"
2

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.

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.