Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Client.forTestnet() returns a WebClient instance with no mirror nodes set. #2263

Open
bguiz opened this issue Apr 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bguiz
Copy link
Contributor

bguiz commented Apr 16, 2024

Description

  1. Edit the code below, listed under "Steps to reproduce" to replace accountId and privateKey with any actual account ID in Hedera Testnet, and corresponding private key.
  2. Run the code in NodeJs
  3. Separately, use the same code in a web application

Expected result, for both NodeJs and browser application:

  • HCS topic subscription is successful, and HCS topic messages get returns as they get added to the HCS topic via the callback

Actual result, when run in NodeJs:

  • ✅ Same as expected result

Actual result, when run in browser application:

  • ❎ Error occurs because client._mirrorNetwork.getNextMirrorNode()
  • ❓The object being initialised appears to not be a Client instance, but rather a WebClient instance
    • perhaps there is some difference in how it should be initialised?

Steps to reproduce

import { Client, TopicMessageQuery } from '@hashgraph/sdk';

const accountId = '0.0.1521'; // actual account on Hedera Testnet
const privateKey = '302e02...'; // actual private key for 0.0.1521
const dummyClient = Client.forTestnet().setOperator(accountId, privateKey);

const subscription = new TopicMessageQuery()
    .setTopicId(topicId)
    .subscribe(dummyClient, callback);

Additional context

Refs

Hedera network

testnet

Version

@hashgraph/sdk@2.42.0

Operating system

macOS

@bguiz bguiz added the bug Something isn't working label Apr 16, 2024
@bguiz
Copy link
Contributor Author

bguiz commented Apr 16, 2024

I've dug into the SDK code a bit further, and found that the WebClient implementation doesn't seem to initialise the mirror network, unlike the NodeClient implementation.

See WebClient#setMirrorNetwork:
https://github.com/hashgraph/hedera-sdk-js/blob/65a2323f/src/client/WebClient.js#L202-L210

And contrast that with NodeClient#setMirrorNetwork:
https://github.com/hashgraph/hedera-sdk-js/blob/65a2323f/src/client/NodeClient.js#L289C5-L312

Was it intentional to have these different implementations for setMirrorNetwork?
Or stated another way - is there something preventing the BrowserClient from accessing mirror nodes?

cc @ochikov @janaakhterov

@pwoosam
Copy link

pwoosam commented Apr 21, 2024

@bguiz I found this GitHub discussion related to the question. grpc/grpc-web#1348

tldr browsers won't support http2 frame fratures required for native gRPC, so servers need to run a grpc-web proxy. Only Hedera's consensus nodes currently run a gRPC-web proxy. So only the consensus nodes can support gRPC connections from the browser.

To support gRPC from the browser, mirror nodes will also need to deploy gRPC-web proxy.

Further explanation from Hedera in this project's readme: https://github.com/hashgraph/hedera-grpcWeb-proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants