I'm using web3auth JS SDK. I have found the example of how to implement switching to different chains. But I need to have access to multiple chains at the same time (e.g. to list user assets from multiple chains). Is there a way to achieve this?
Originally posted by:
yurayavorski Check the discussion at:
https://github.com/orgs/Web3Auth/discussions/454
You can export the key from the web3auth provider and instantiate your own provider for the different chains needed
Originally posted by:
YZhenY
Hey @yurayavorski
We don't have an example for this case, but I can explain to you how the code will look like. You can use this private key provider: https://web3auth.io/docs/sdk/web/providers/other to get the private key of the user. Now suppose I want to use it for StarkEx and Tezos. Now I will make two different functions for getting StarkEx keys and Tezos keys like these:
getStarkAccount = async (): Promise<any> => {
try {
const privateKey = await this.provider.request({ method: “private_key” });
const keyPair = starkwareCrypto.ec.keyFromPrivate(privateKey, “hex”);
const account = starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true, “hex”), “hex”);
return account;
} catch (error) {
return error;
}
};
getStarkKey = async (): Promise<string | undefined> => {
try {
const account = await this.getStarkAccount();
const publicKeyX = account.pub.getX().toString(“hex”);
return publicKeyX;
} catch (error) {
return error as string;
}
};
getTezosKeyPair = async (): Promise<any> => {
try {
const privateKey = (await this.provider.request({ method: "private_key" })) as string;
const keyPair = tezosCrypto.utils.seedToKeyPair(hex2buf(privateKey));
return keyPair;
} catch (error) {
return error;
}
};
Afterwards, you can use these keys for each blockchain to make calls accordingly. You can check our StarkEx and Tezos blockchain pages to know how to make calls.
Originally posted by:
yashovardhan