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) 
chen Crush
  • 11
  • 5

1 Answers1

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
Ismael
  • 30,570
  • 21
  • 53
  • 96