Resolve Glow ID via Chain
You can easily go from Glow ID → wallet and back.
When you register a Glow ID, you create an account on chain that points to the wallet you registered with.
Glow ID Handle → Wallet Address
To go from a Glow ID handle, you take the following steps:
- Calculate the PDA where the Glow ID information is stored,
findProgramAddressSync
below - Get the account data from the address calculated in 1
- Read the account data to get the wallet address
The Glow ID account will also have other information about the user — metadata, verified Twitter, etc.
import { Connection, PublicKey } from "@solana/web3.js";
import { Buffer } from "buffer";
const handleBuffer = Buffer.alloc(16);
handleBuffer.write(handle); // "victor"
// This publicKey stores the data for the Glow ID
const [publicKey] = PublicKey.findProgramAddressSync(
[Buffer.from("handle@"), handleBuffer],
new PublicKey("GLoW6kDXmQHFjtQQ44ccmXjosqrKkE54bVbUTA4bA3zs")
);
const connection = new Connection("https://api.mainnet-beta.solana.com");
const account = await connection.getAccountInfo(publicKey);
const walletBytes = account!.data.slice(41, 41 + 32);
const wallet = new PublicKey(new Uint8Array(walletBytes));
console.log(wallet.toBase58()); // vicFprL4kcqWTykrdz6icjv2re4CbM5iq3aHtoJmxrh
Wallet Address → Glow ID Handle
When someone registers for Glow ID, we create a wallet info PDA derived from the wallet seeds and store the current handle there. So to get the current handle:
- you calculate the PDA for the given wallet address
- you get data in that account
- that data has the handle, so you just need to parse it out
You can also get the wallet address via getProgramAccounts
but that is slower and will become less performant over time.
import { Connection, PublicKey } from "@solana/web3.js";
import { Buffer } from "buffer";
const pubkey = new PublicKey("64WMAwJ2zPw9uuPQSeQCKwKqeTne6z2kzCjnNczp7My8");
const [walletInfoPkey] = PublicKey.findProgramAddressSync(
[Buffer.from("wallet@"), pubkey.toBuffer()],
new PublicKey("GLoW6kDXmQHFjtQQ44ccmXjosqrKkE54bVbUTA4bA3zs")
);
const walletInfoAccount = await connection.getAccountInfo(walletInfoPkey);
const handleBytes = walletInfoAccount!.data
.slice(41, 41 + 16)
.filter((byte) => byte !== 0);
const handle = Buffer.from(handleBytes).toString("utf-8");
console.log(handle); // "thomas"
GitHub Repo for Scripts
You can see these scripts and more in a helpful GitHub repo: https://github.com/glow-xyz/glow-id-utils
Updated 5 months ago