Skip to main content
edited tags
Link
Rob Hitchens
  • 55.6k
  • 11
  • 91
  • 146
Source Link

difference between contract creation in web3 and in solidity

  1. I created a contract named Pepito by calling new in web3:
   import Pepito from "./contracts_abi/Pepito.json";
   const instance = new web3.eth.Contract(
        Pepito.abi,
        address,
      );
  1. Inside Pepito.sol there is a function that calls newin solidity
   import "./PepitoDisguise.sol";
   function createPepitoDisguise() public returns(PepitoDisguise) {
        PepitoDisguise pepitoDisguise = new PepitoDisguise(owner);
        return pepitoDisguise;
    }
  1. I call createPepitoDisguise from web3 by calling the function inside Pepito
   const pepitoDisguise = await instance.methods.createPepitoDisguise();

My question is: how come that in case 1 a contract is returned and in case 2 a transaction object (https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#id24) is returned?

The answer is important for me because when a contract Pepito is returned, I can call a function of Pepito but when a transaction object is returned after new PepitoDisguise, I cannot. I need to call a function also in PepitoDisguise. How can I get this new Contract?