0

I have tried to use sha3 but it return error since invalid address. Here is my code. The sha3 returns 32 bytes address. I wonder is there other function that returns 20 bytes .

var to_add = web3.sha3(str);
web3.eth.sendTransaction({from: '0xC5b0f45d8533909a80eA45Ed2FC42bd36C1Cccac', data:str,to:to_add},function(err, transactionHash) 
7
  • What's str??? Commented Nov 18, 2020 at 17:45
  • web3.sha3 seems pretty old BTW. Are you still on web3.js v0.x? Commented Nov 18, 2020 at 17:47
  • @goodvibration str is user logging information. I need to store them in recipient(to address) . Yes I am using web3.js v0 since class requires that. thanks
    – chen Crush
    Commented Nov 18, 2020 at 17:51
  • What is its value, is what I meant to ask. Commented Nov 18, 2020 at 17:54
  • The value is not defined. It depends on which function user call. Bascially, the value can be "user a log in", or "user a log out "etc. So the length is not fixed
    – chen Crush
    Commented Nov 18, 2020 at 18:09

1 Answer 1

0

Addresses are computed from a private key, see How is the address of an Ethereum contract computed?. If you are trying to generate them from a random hexadecimal string it is very likely you will not be able to access the funds transferred.

If you already have an hexadecimal string that comes from a valid address and its checksum is incorrect you can fix it with web3.utils.toChecksumAddress.

> badAddress = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
> goodAddress = web3.utils.toChecksumAddress(badAddress);
> console.log(goodAddress);
0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa

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.