blockchainethereumweb3jstron

Convert wallet address on Tron


I need to get the wallet address from the trc-20 transaction on the Trone network.

I found out that this info can be taken from the input field. I use web3.js to parse this field and get an address like

0xee564858c4874cac2d1fff98c1eabba915f50b2f

But I need it to be like

TXhRBjb8GDnodu3VY6vgmNXcGnLpQhm9NW

I can't find the info how to convert it


Solution

  • tronWeb.address.toHex : Convert Base58 format addresses to Hex

    const convertedAddress = tronWeb.address.toHex(givenAddress);
    

    tronWeb.address.fromHex : Convert Hexstring format address to Base58 format address

    const convertedAddress = tronWeb.address.fromHex(givenAddress);
    

    tronWeb.address.fromPrivateKey : Derive its corresponding address based on the private key

    const givenAddress = tronWeb.address.fromPrivateKey(privateKey);
    

    source link