Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

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();
    }
}
question from:https://stackoverflow.com/questions/65860069/pass-constant-tron-address-in-solidity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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')


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...