Solana Connect Integration
support version >=0.1.3
This documentation will guide you in the easiest way to connect your This guide will walk you through the easiest way to connect your DApp with the UXUY Wallet application.
Using the SDK
You can use the @uxuycom/web3-tg-sdk
to connect your DApp to the UxuyWallet application.
Installation
Install the UXUY SDK packages via npm:
npm install @uxuycom/web3-tg-sdk @solana/web3.js @solana/spl-token
use Solana Connect
import { WalletTgSdk } from '@uxuycom/web3-tg-sdk';
const { solana } = new WalletTgSdk({
// injected: true; // inject provider from window.solana if not provided
// metaData: {
// name: 'Your DApp Name',
// icon: 'https://example.com/icon.png'
// }
});
const solanaProvoder = solana
isConnected
const isConnected = solanaProvider.isConnected
const isConnected = solanaProvider.connected;
publicKey
const address = solanaProvider.publicKey.toString();
Connecting to the Wallet
await solanaProvoder.connect();
solanaProvider.publicKey.toString()
getAccount
const address = await solanaProvider.getAccount()
Signing Messages
When a web application is connected to UXUY Wallet, it can also request that the user signs a given message. Applications are free to write their own messages which will be displayed to users from within UXUY Wallet.'s signature prompt. Message signatures do not involve network fees and are a convenient way for apps to verify ownership of an address.
For more information on how to verify the signature of a message, please refer to tweetnacl-js.
try {
const { publicKey, signature } = await solanaProvider.signMessage(Buffer.from("0x1232131").toString("hex"));
} catch (e) {
// Error handling
}
General Transfer
For making transfers using Solana, refer to examples.
import { TOKEN_PROGRAM_ID getMint } from '@solana/spl-token';
import { Connection, PublicKey, SystemProgram, Transaction, PublicKey } from '@solana/web3.js';
const connection = new Connection("<your rpc endpoint>");
const transaction = new Transaction();
const fromAddress= solanaProvider.publicKey.toString()
const fromPubkey = new PublicKey(fromAddress)
const toPubkey = new PublicKey("ADVQ12wFnABx7gxFJHc6YTh4MYG6DBWH8HcDUhoaQkQq");
transaction.add(
SystemProgram.transfer({
fromPubkey: fromPubkey,
toPubkey: toPubkey,
lamports: 0.0001 * 1e9, // 10^9 = 1 SOL
})
)
transaction.feePayer = fromPubkey; //feePayer
transaction.recentBlockhash = (await connection.getRecentBlockhash())?.blockhash;
const signedTransaction = await solanaProvider.signTransaction(transaction)
await connection.sendRawTransaction(signedTransaction.serialize());
disconnect
solanaProvider.disconnect()