1

I am trying to get this code to work with the Tron network, here is a sample of what I seen online

function isContract(address account) internal view returns (bool) {
    // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
    // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
    // for accounts without code, i.e. `keccak256('')`
    bytes32 codehash;
    bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
    // solhint-disable-next-line no-inline-assembly
    assembly { codehash := extcodehash(account) }
    return (codehash != accountHash && codehash != 0x0);
}

This is my implementation of it in for Tron

    function isContract(address account) internal view returns (bool) {
    // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
    // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
    // for accounts without code, i.e. `keccak256('')`
    bytes32 codehash;
    bytes32 accountHash = convertFromTronInt(THgQd3Z3nZuvVNBL9HcAyiutrpsigVKPT1);
    //THgQd3Z3nZuvVNBL9HcAyiutrpsigVKPT1;
    // solhint-disable-next-line no-inline-assembly
    assembly { codehash := extcodehash(account) }
    return true;
}

function convertFromTronInt(uint256 tronAddress) public view returns(address){
  return address(tronAddress);

}

Is there is any better way of making the same check from Tron tokens or is my solution viable?

1 Answers1

0

You can use the trongrid API to get contract details (if it is affordable for your use case). No data can be treated as the address is not a contract.

curl --request POST \
 --url https://api.trongrid.io/wallet/getcontractinfo \
 --header 'accept: application/json' \
 --header 'content-type: application/json' \
 --data '
{
  "value": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
  "visible": true
}
'
Nick
  • 144
  • 1
  • 4