Open ixa94 opened 2 years ago
Using LcdClient
(and anything else from @cosmjs/launchpad) is a dead end. This package is for connecting to Cosmos SDK 0.37–0.39 backends only and is about to be removed.
If you have questions to @cosmjs/stargate related integration, please format the code properly to make it readable. See https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks and https://commonmark.org/.
@webmaster128 i have formatted the code
@webmaster128 `// if i use @cosmjs/stargate
import { SigningStargateClient, } from '@cosmjs/stargate'; import { keplrChainId } from 'appConstants';
async function connectKeprl(): Promise<SigningStargateClient | false> { if (!window.keplr) { return false; }
await window.keplr.enable(keplrChainId);
const offlineSigner = window.keplr.getOfflineSigner(keplrChainId);
const accounts = await offlineSigner.getAccounts();
const cosmJS = await SigningStargateClient.connectWithSigner( 'https://rpc.my_tendermint_rpc_node', offlineSigner, ); const account = await cosmJS.getAccount(accounts[0].address); console.log('account:', account);
////How can I get balance from my wallet? //i have error like this POST https://rpc.my_tendermint_rpc_node/ net::ERR_NAME_NOT_RESOLVED // so how can I resolve these errors`
https://rpc.my_tendermint_rpc_node
is a placeholder. You need to replace it with our Tendermint RPC URL.
@webmaster128 Hey Could you please send me your Tendermint RPC URL. Because I couldn’t find it by myself. Thank you!
If you want to connect to the Cosmos Hub, you can try https://rpc.cosmos.network/. There are many other RPC endpoints out there, but you'd have to go and search for them.
@webmaster128 I have some questions 1)I want to get balance from my wallet.Am I using the correct code? 2)When I am trying to call "connectWithSigner" I catch CORS error,so how can I resolve it. I'd be grateful If you helped me.Thanks a lot.
import { SigningStargateClient } from '@cosmjs/stargate';
import { keplrChainId } from 'appConstants';
async function connectKeprl(): Promise<SigningStargateClient | false> {
if (!window.keplr) {
return false;
}
await window.keplr.enable('cosmoshub-4');
const offlineSigner = window.keplr.getOfflineSigner('cosmoshub-4');
const accounts = await offlineSigner.getAccounts();
const cosmJS = await SigningStargateClient.connectWithSigner(
'https://rpc.cosmos.network',
offlineSigner,
);
console.log(cosmJS.getBalance(accounts[0].address, 'uatom'));
return cosmJS;
await
the result of getBalance
: const balance = await cosmJS.getBalance(accounts[0].address, 'uatom')
. The rest LGTM auf first glance.@webmaster128 I'm trying to do the way you advised, but I get the CORS again. Probably I'm writing or using something in a wrong way.
import {
SigningStargateClient,
} from '@cosmjs/stargate';
import { keplrChainId } from 'appConstants';
async function connectKeprl(): Promise<SigningStargateClient | false> {
if (!window.keplr) {
return false;
}
await window.keplr.enable(keplrChainId);
const offlineSigner = window.keplr.getOfflineSigner(keplrChainId);
const accounts = await offlineSigner.getAccounts();
const cosmJS = await SigningStargateClient.connectWithSigner(
'https://rpc-cosmoshub.keplr.app',
offlineSigner,
);
const balance = await cosmJS.getBalance(accounts[0].address, 'uatom');
console.log(balance);
Yeah, sorry this does not work too. You have to find a Tendermint RPC node that has CORS configures for access from any origin for the Cosmos Hub. There is no obvious solution to that. You need to ask your war through Cosmos Hub community channels. Maby you find some nice validators that provide such an endpoint.