Hi, i am using near chain but i am not able to get account address like someone.near and I am on testnet
async getAccounts(): Promise<any> {
try {
console.log("this.provider", this.provider);
console.log(this.privateKey, "this . private key");
const { getED25519Key } = await import("@toruslabs/openlogin-ed25519");
// const privateKeyEd25519 = getED25519Key(this.privateKey).sk.toString(
// "hex"
// );
console.log(this.privateKey);
// console.log(privateKeyEd25519);
// Get user's Solana's public address
await this.provider.setupProvider(this.privateKey);
const privateKeyEd25519Buffer = Buffer.from(this.privateKey, "hex");
// Convert the private key to base58
const bs58encode = utils.serialize.base_encode(privateKeyEd25519Buffer);
console.log("π ~ Near ~ getAccounts ~ bs58encode:", bs58encode);
// Convert the base58 private key to KeyPair
const keyPair = KeyPair.fromString(`ED25519:${bs58encode}`);
console.log("π ~ NearRpc ~ getAccounts ~ keyPair:", keyPair);
// publicAddress
const publicAddress = keyPair?.getPublicKey().toString();
console.log("π ~ NearRpc ~ getAccounts ~ publicAddress:", publicAddress);
// accountId is the account address which is where funds will be sent to.
const accountId = utils.serialize.base_decode(
publicAddress.split(":")[1]
);
console.log("π ~ NearRpc ~ getAccounts ~ accountId:", accountId);
let address = Buffer.from(accountId.buffer).toString("hex");
// publicAddress
const publicAddress1 = keyPair?.getPublicKey().data || [];
console.log(
"π ~ NearRpc ~ getAccounts ~ publicAddress1:",
publicAddress1
);
console.log("π ~ NearRpc ~ getAccounts ~ address:", address);
const accountId1 = Buffer.from(bs58encode || []).toString("hex");
console.log("π ~ NearRpc ~ getAccounts ~ accountId1:", accountId1);
return address;
} catch (error) {
console.log("π ~ NearRpc ~ getAccounts ~ error:", error);
throw new Error(error);
}
}
can somebody guide me what should I do?