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?

7 Answers 7

9

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

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

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/

0

You can use the bytes32 library from npm https://npm.devtool.tech/bytes32

$ npm install bytes32

$ npx bytes32
0x0000000000000000000000000000000000000000000000000000000000000000

$ npx string
0x737472696e670000000000000000000000000000000000000000000000000000

0

I made an online utility for via versa conversion of String to Bytes32. It is client side also, so everything runs on the browser.

Online String to Bytes32 Converter

0

You can use Web3 tools created by Neptune Mutual which has String to Bytes32 Converter and vice versa.

https://neptunemutual.com/web3-tools/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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