-2

So, I've a contract which deploys using create2 i.e., custom salt. Its working perfectly in Ethereum but with Tron it's not. When its called, the result of the contract ( which is created by create2 ) is empty. The contract ABI and Bytecode both shows null. I dont know why its happening. Am I missing something?

Here is the part of the code of my contract

function deploy(address _owner, uint256 _salt) public returns (address addr) {
        bytes memory bytecode = getBytecode(_owner);
        assembly {
            addr := create2(
                0,
                add(bytecode, 0x20),
                mload(bytecode),
                _salt
            )

            if iszero(extcodesize(addr)) {
                revert(0, 0)
            }
        }

        emit Deployed(addr, _salt);
    }

function getBytecode(address _owner) public pure returns (bytes memory) {
    bytes memory bytecode = type(Forwarder).creationCode;
    return abi.encodePacked(bytecode, abi.encode(_owner));
}

Forwarder is my Contract

This is one of my contract which is deployed by create2

If anyone need anymore info, Let me know. I wanna solve this.

Sandeep
  • 545
  • 6
  • 9
  • Could you solved your problem? – Hamid Naghipour Jun 02 '22 at 12:20
  • @HamidNaghipour I'm testing it. Contacted the support team of Tron. They accepted it and said its a bug in their tron IDE but the bytecode exists onchain. They said to try calling programatically like in node js we get bytecode via contract address and all things. I'm testing that. Will update this once I got success – Sandeep Jun 11 '22 at 08:03

1 Answers1

0

So, we cannot get ABI and bytecode of a contract deployed using create2 said by tron support team. and they provided a solution i.e.,

let instance = await tronWeb.contract().at("TREwN2qRkME9TyQUz8dG6HfjEyKGMPHAS5");
instance.loadAbi([{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]);
let res = await instance.totalSupply().call({_isConstant:true})

so we can get the instance from contract address and load the ABI and then we can call the contract function and perform operation.

Sandeep
  • 545
  • 6
  • 9