Search code examples
soliditytron

Pass constant tron address in solidity


How to use TRON address in solidity. I am unable to use deployed smart contract by TRON address. How its possible. Please help.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;

abstract contract TRC20 {
    function decimals() public virtual returns (uint8);
}

contract Matrix {

    function greet() public payable returns (uint8) {
        TRC20 t = TRC20(TKssrn5v8ephdmJbh7UYaUeoR4L1d4ZXds);
        return t.decimals();
    }
}

Solution

  • TKssrn5v8ephdmJbh7UYaUeoR4L1d4ZXds address is in base58 format, you'll need to convert it into hex format.

    Using your example, you can change greet function to take an address argument.

        function greet(address _address) public payable returns (uint8) {
            TRC20 t = TRC20(_address);
            ...
    

    You can then convert the address from base58 format to hex format using tronWeb's to hex function. tronweb.address.toHex('TKssrn5v8ephdmJbh7UYaUeoR4L1d4ZXds')