2

Lets say i have a contract which includes a function that deploys new ERC721 contract:

function createCollection(
    uint256 _price, uint256 _maxSupply, string memory _name, string memory _symbol, 
    address _requsetFrom, string memory _uri, bytes32 salt
    ) external payable returns(address)  {
        if (msg.value < s_createFee) {
            revert CollectionCreator__InsufficientAmount();
        }
        CollectionV2 newNft = new CollectionV2(_name,_symbol,_price,_maxSupply,_requsetFrom, _uri);
        address _contractAddress = address(newNft);
        ownerToCollection[_requsetFrom].push(_contractAddress);
    emit NewCollection(_requsetFrom, _contractAddress);
    return(_contractAddress);
}

And i returned the address of new contract, but when i want to get address of new contract in the backend it returns me the transaction:

const Collection = await ERC721Creator.createCollection(10,100,'test','tst',deployer.address,'someuri')
  await Collection.wait(1)
  console.log(Collection);

It returns me a ton of information about this transaction, what i must to do? thanks


According to Rohan answer i got address this way:

const Collection = await ERC721Creator.createCollection(10,100,'test','tst',deployer.address,'someuri')
  const tx = await Collection.wait(1)
  const newContractAddress = tx.events[0].args[1]
3

1 Answer 1

2

I believe all you need to do is assign your await Collection.wait(1) to a variable such as

const txReceipt = await Collection.wait(1)

Then you can console.log your address like this

console.log("Your new address:", txReceipt.events[0].args._contractAddress)

you may need to use a different events index depending on if you make any contract function calls that emit events inside them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.