Resolve Transaction Result in React

Hi @cryptokid,

I have one issue using morails.

I need to get the result(address) after run write function with return value(address) on react.

Here is my code:
on Contract,
function createNewCollection(…) external returns (address) {
address newContract = …;

return newContract;
}

on react,
let ops = {
contractAddress: marketAddress,
functionName: “createNewCollection”,
abi: contractABI,
params: {
collectionType: collectionType,
_name: title,
_symbol: symbol,
_uri: metadataUrl
}
};
await contractProcessor.fetch({
params: ops,
onSuccess: async (result) => {
let collectionAddr = await result.wait();
console.log(“new collection address:”, collectionAddr);
}
}

But, collectionAddr is still transction, not address.
image

How can I fix this problem?

I hope your quick help.

Regards,

What you see in your console is correct since you expect your result to be a TransactionReceipt Object.

Now let’s find the piece of information you want to display, could you please open the following section of the object you got in your console:

logs: (4) [ {...} {...} {...} {...} ]

I am positive you will find the new contract address there since I recognize the contract you are interacting with.

To access the information you want inside an object, you need to describe it. Say you want to access the message sender, you would have to do the following:

console.log(result.from)

The info you need is somewhere inside:

console.log(collectionAddr.logs[1])

I need the new address returning from contract after created new collection(write function, not read function). (you can refer my code above)

My marketplace contract was deployed on bsc testnet.

Here is my logs:

As you can see, there are 4 logs, and then 3 logs has the same address and log[2] is different address.
So, can you explain about these logs in detail?

Thanks

@menezesphill @cryptokid
Really, I need your quick help and answer.

those logs, are not generated by your contract?

what in particular you don’t understand from those logs?

The logs is coming from “await result.wait();”.
There is not “newContract” value returned from contract.
How can I get the returned “newContract” value(new collection address) from the transaction?

Here is my code: (contract function is a write function, not read function)
on Contract,
function createNewCollection(…) external returns (address) {
address newContract = …;

return newContract;
}

on react,
let ops = {
contractAddress: marketAddress,
functionName: “createNewCollection”,
abi: contractABI,
params: {
collectionType: collectionType,
_name: title,
_symbol: symbol,
_uri: metadataUrl
}
};
await contractProcessor.fetch({
params: ops,
onSuccess: async (result) => {
let collectionAddr = await result.wait();
console.log(“new collection address:”, collectionAddr);
}
}

First, please look here to see how to post code on forum: READ BEFORE POSTING - How to post code in the forum

do you have access to the source code of the contract for which you call that function?

@cryptokid
Sure, yeah, I can access.
so, should I emit event when created new collection and then analyze the result?

yes, you can modify/write that contract, then you can emit a specific event with that information and then you can parse it from that response.

the address in event is the address that emits the event, and in topics and data you can see the extra info that is emitted by that event as parameters

1 Like

Okay, Thanks your help.

The address in the first two logs are the ones you are looking for. This contract is a Corsac NFT Factory and these two first logs correspond respectively to contract ownership transfer from Zero address to the Factory and from the Factory to you. The data you need is collectionAddr.logs[0].address or collectionAddr.logs[1].address

1 Like

@menezesphill
Great, really thanks.