multiversx / mx-sdk-js-core

MultiversX SDK for interacting with the MultiversX blockchain (in general) and Smart Contracts (in particular).
https://multiversx.github.io/mx-sdk-js-core/
Other
60 stars 37 forks source link

Getting error: cannot find event of type ESDTSetRole #294

Closed itsabinashb closed 1 year ago

itsabinashb commented 1 year ago

Hi, i am having a issue related to parseSetSpecialRole(). This is how i am doing the transaction:

const transaction2 = factory.setSpecialRoleOnFungible({
    manager: signer.getAddress(),
    user: signer.getAddress(),
    tokenIdentifier: tx1OnOutcome.tokenIdentifier,
    addRoleLocalMint: true,
    addRoleLocalBurn: true,
  });

  const tx2 = await processTransaction(transaction2, signer, signerAccount);
  const tx2Hash = await provider.sendTransaction(tx2);
  const tx2OnNetwork = await watcher.awaitCompleted(tx2);
  console.log(`tx2 completed`);
  console.log('Hash2: ', tx2Hash);
  const tx2Outcome = parser.parseSetSpecialRole(tx2OnNetwork);

async function processTransaction(transaction, signer, signerAccount) {
  console.log('signer address in processTransaction:', signer.getAddress().toString());
  await transaction.setNonce(signerAccount.getNonceThenIncrement());
  let serializedTransaction = await transaction.serializeForSigning(); // Serializing the transaction to a sequence of bytes, preparing it to be signed
  let transactionSignature = await signer.sign(serializedTransaction); // signing the transaction
  transaction.applySignature(transactionSignature); // applying the signature on the transaction
  return transaction;
}

The error i got :

TransactionCompletionStrategy.isCompleted(), found hyperblock nonce: 5828203
tx2 completed
Hash2:  dace5af85aa70a861426d98a0292e794571f640726587851fca95acd74ac86d7
/home/abinash/Desktop/issueToken (copy)/node_modules/@multiversx/sdk-core/out/tokenOperations/tokenOperationsOutcomeParser.js:141
            throw new errors_1.ErrCannotParseTransactionOutcome(transaction.hash, `cannot find event of type ${identifier}`);
                  ^

ErrCannotParseTransactionOutcome [Error]: cannot parse outcome of transaction dace5af85aa70a861426d98a0292e794571f640726587851fca95acd74ac86d7: cannot find event of type ESDTSetRole
    at TokenOperationsOutcomeParser.findSingleEventByIdentifier (/home/abinash/Desktop/issueToken (copy)/node_modules/@multiversx/sdk-core/out/tokenOperations/tokenOperationsOutcomeParser.js:141:19)
    at TokenOperationsOutcomeParser.parseSetSpecialRole (/home/abinash/Desktop/issueToken (copy)/node_modules/@multiversx/sdk-core/out/tokenOperations/tokenOperationsOutcomeParser.js:34:28)
    at MakeToken (/home/abinash/Desktop/issueToken (copy)/index.js:82:29) {
  inner: undefined
}

But the strange thing is my transaction is showing successful for special role setting, please see here: https://devnet-explorer.multiversx.com/transactions/dace5af85aa70a861426d98a0292e794571f640726587851fca95acd74ac86d7

The log: image Please help me on this.

andreibancioiu commented 1 year ago

Hello!

Sometimes, the watcher is informed that the transaction is complete, but the events might still be missing at that very moment.

You can set a patienceMilliseconds parameter when creating the watcher.

watcher = new TransactionWatcher(provider, { patienceMilliseconds: 8000 });

Additionally, you can also switch to using an ApiNetworkProvider (instead of a ProxyNetworkProvider) and connect it to https://devnet-gateway.multiversx.com.

For reference:

Let us know how it goes :pray:

itsabinashb commented 1 year ago

Hi, thanks for your reply, i just removed this line:const tx2Outcome = parser.parseSetSpecialRole(tx2OnNetwork); and i worked.