Replies: 2 comments 1 reply
-
can anyone answer my question here? |
Beta Was this translation helpful? Give feedback.
-
Hey @danieljao Please take a look at https://web3auth.io/docs/connect-blockchain/solana. While using the Web3Auth Web SDK for Solana you get a standard provider for Solana containing functions to help you make blockchain calls via the @solana/web3.js library. A sample signTransaction would look like below: import { Connection, LAMPORTS_PER_SOL, PublicKey, SystemProgram, Transaction } from "@solana/web3.js";
import { Web3Auth } from "@web3auth/modal";
import { SolanaWallet } from "@web3auth/solana-provider";
const web3auth = new Web3Auth({
clientId: "YOUR_WEB3AUTH_CLIENT_ID", // get it from Web3Auth Dashboard
chainConfig: {
chainNamespace: "solana",
chainId: "0x1", // Please use 0x1 for Mainnet, 0x2 for Testnet, 0x3 for Devnet
rpcTarget: "https://rpc.ankr.com/solana",
displayName: "Solana Mainnet",
blockExplorer: "https://explorer.solana.com",
ticker: "SOL",
tickerName: "Solana Token",
},
});
await web3auth.initModal();
const web3authProvider = web3auth.connect();
const solanaWallet = new SolanaWallet(web3authProvider); // web3auth.provider
// solanaWallet is from above
const connectionConfig = await solanaWallet.request({
method: "solana_provider_config",
params: [],
});
const connection = new Connection(connectionConfig.rpcTarget);
const accounts = await solanaWallet.requestAccounts();
const block = await connection.getLatestBlockhash("finalized");
const TransactionInstruction = SystemProgram.transfer({
fromPubkey: new PublicKey(accounts[0]),
toPubkey: new PublicKey(accounts[0]),
lamports: 0.01 * LAMPORTS_PER_SOL,
});
const transaction = new Transaction({
blockhash: block.blockhash,
lastValidBlockHeight: block.lastValidBlockHeight,
feePayer: new PublicKey(accounts[0]),
}).add(TransactionInstruction);
const signedTx = await solanaWallet.signTransaction(transaction);
console.log(signedTx.signature);
To show the modal popup upon making any transaction, you can use Torus-Wallet Adapter with Web3Auth. Please have a look at https://web3auth.io/docs/sdk/web/adapters/torus-evm |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, im new to web3auth, and im trying to integrate with solana. I have few questions:
How do i sign / send transaction? Should i get the "private key" to generate the keypair so i can call the
connection.sendTransaction(tx, [keypair],
Is there a way that this can be confirm with the modal popup? like how Phantom works?
Beta Was this translation helpful? Give feedback.
All reactions