Transection Issue Of getgrpcClient and getJsonRpcClient

I am trying to send the transection while I wait for transection due to getJsonRpcClient is deprecated since i tried to do it with getgrpcClient still facing error the code is.
function _wait(provider, txnHash, res, rej) {
setTimeout(() => {
provider
// .getJsonRpcClient()
.getGrpcClient()
.getTransactionStatus(txnHash)
.then(txnStatus => {
if (!txnStatus) {
return rej(“Transaction Status is null”);
}

    console.info(`txn : ${txnHash}, status: ${txnStatus?.status}`);

    if (txnStatus?.status === TransactionStatusEnum.Finalized) {
      return res(txnStatus.outcomes);
    }

    _wait(provider, txnHash, res, rej);
  })
  .catch(err => rej(err));

}, 1000);
}
with using getGrpcClient if a face this error
typeError:A.getGrpc(…).getTransactionStatus is not a function
If i use the getJsonRpcClient() i face this error
typeerror:A.getJsonRpcClient is not a function

I am calling it in this while I getting the Provider and txnhash
function waitForTransaction(provider, txnHash) {
return new Promise((res, rej) => {
_wait(provider, txnHash, res, rej);
});
}

Hi hassan.

The JSON RPC client has been removed from the wallet API after being deprecated for a long while, so the only way to communicate with a Concordium node is through GRPC.

The recommended way to do this with the our Concordium wallet for web is described at the bottom of the documentation for @concordium/browser-wallet-api-helpers, which also documents the interface of the Concordium Wallet API. Please note that the latest version of this has @concordium/web-sdk@7 is a peer dependency here, meaning you need to have this installed in your project as well.

Since you have a reference to a provider in your code, I assume you’re using @concordium/browser-wallet-api-helpers in your project. Which version of this package are you using?

If you get your dependencies up to date by doing the following:

npm install --save @concordium/browser-wallet-api-helpers @concordium/web-sdk # or yarn if you use that

You should be able to do the following (which I think is what you’re trying to achieve):

import { detectConcordiumProvider } from '@concordium/browser-wallet-api-helpers';
import { ConcordiumGRPCClient } from '@concordium/web-sdk';
...

const provider = await detectConcordiumProvider();
const client = new ConcordiumGRPCClient(provider.grpcTransport);
const transactionHash = await provider.sendTransaction(...); // wait for user approval in wallet
const status = await client.waitForTransactionFinalization(transactionHash); // wait for transaction to finalize

Please let me know if that works for you, or if you face any other issues while trying to do this.

/Søren

thanks for your consideration in this matter I have done that thanks for your support if you can look at this function I am facing a problem like I don’t get the txnstatus receiving [Object,Object] how can i get the status in console.info in my code the code is.

function _wait(provider, txnHash, res, rej) {
console.log(provider, txnHash, “params fro wait”);
setTimeout(() => {
provider
.getGrpcClient()
.waitForTransactionFinalization(txnHash)
.then(txnStatus => {
if (!txnStatus) {
return rej(“Transaction Status is null”);
}

    console.info(`txn : ${txnHash}, status: ${txnStatus?.status}`);

    if (txnStatus?.status === TransactionStatusEnum.Finalized) {
      return res(txnStatus.outcomes);
    }

    _wait(provider, txnHash, res, rej);
  })
  .catch(err => rej(err));

}, 1000);
}

@concordium/browser-wallet-api-helpers”: “2.2.0”,
@concordium/web-sdk”: “3.2.0”,

Instead including the transaction status object in your string, do this instead:

console.info(`txn : ${txnHash}, status:`, txnStatus?.status);

That should make your console show the details.

Okay let me try it but thanks for your support really appreciate your responses.

txn : 52603ffc9625f377c08ed7263752ce2ad85047df904da9159ed1888e8b26ee0e, status: undefined
this is what i am getting still undefine

The type returned by waitForTransactionFinalization is an object that has a status property on it. Have a look here at the function signature: ConcordiumGRPCClient | Concordium JS-SDK

You can see from the signature, that it returns a Promise which resolves to a type of: BlockItemSummaryInBlock | Concordium JS-SDK

You can also inspect the object by simply

console.info(`txn : ${txnHash}, status:`, txnStatus);

I really appreciate your effort and helping. I am know don’t using my custom wait function for wait transection know I am simply just doing this at the end of the Update contract function.

//const outcomes = await waitForTransaction(provider, txnHash);
const outcomes = await provider.getGrpcClient().waitForTransactionFinalization(txnHash);
console.log(outcomes, “outcomes”);
// return ensureValidOutcome(outcomes);

return outcomes;

My functions run properly after I implement the above mention logic

My functions run properly after I implement the above mention logic.