1

so at the end of lesson2 is a challenge to change the connection url to main net and check the balance for of the address toly.sol for example.

I found that, I have to change the Connection url to: "https://api.mainnet-beta.solana.com" in order to connect to main net. But when I type: npx esrun check-balance.ts toly.sol. The console shows me an error. And I understand that, because toly.sol is not a public key. But How do I find out the public key of toly.sol?

This is the code from my check-balance.ts:

import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";

const suppliedPublicKey = process.argv[2];
if (!suppliedPublicKey) {
  throw new Error("Provide a public key to check the balance of!");
}

const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");

const publicKey = new PublicKey(suppliedPublicKey);

const balanceInLamports = await connection.getBalance(publicKey);

const balanceInSOL = balanceInLamports / LAMPORTS_PER_SOL;

console.log(
  `✅ Finished! The balance for the wallet at address ${publicKey} is ${balanceInSOL}!`
); 

What am I missing here?

Greetings Lukan

1
  • Same here. Don't really see a point of such "challenges"... So there is no an online service to convert those .sol-things to public keys?
    – Onkeltem
    Commented Oct 8 at 22:25

1 Answer 1

0

The issue is that you are passing in an SNS toly.sol instead of an actual solana address which is probably erroring out with non-base 58 character

To fix this, use an actual b58 address e.g devu5C7Jg52KXd2Uyo5okGESYyKtQPMx8sme6vM11xK or check out the bonfida SDK which is the main provider of .sol domains on solana.

You can use their sdk, documented here to check what address toly.sol maps to https://sns.guide/domain-name/devnet.html

import { getDomainKeySync, NameRegistryState } from "@bonfida/spl-name-service";

const domainName = "toly"; // With or without the .sol at the end

// Step 1
const { pubkey } = getDomainKeySync(domainName);

// Step 2
// The registry object contains all the info about the domain name
// The NFT owner is of type PublicKey | undefined
const { registry, nftOwner } = await NameRegistryState.retrieve(
  connection,
  pubkey
);

if (!nftOwner) {
  throw new Error("Provide a public key to check the balance of!");
}

const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");

const publicKey = new PublicKey(nftOwner);

const balanceInLamports = await connection.getBalance(publicKey);

const balanceInSOL = balanceInLamports / LAMPORTS_PER_SOL;) {
  throw new Error("Provide a public key to check the balance of!");
}

console.log(balanceInSol)
1
  • Hi Jimii, thanks for your advice. I had a look into the sns guide and could gain some knowledge out of it. It looks like sns domains is a whole rabbit hole to get into. I installed their node package and tried your code, but the 2 imports({ getDomainKeySync, NameRegistryState } ) are underlined and I get: Module '"@bonfida/spl-name-service"' has no exported member 'getDomainKeySync'.ts(2305) . Is your code from chatgpt? I guess sns domains are not sooo important for me at the moment, but thank you. Commented Jul 16 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.