Posted By : Aman
Solana blockchain supports SOL tokens and SPL customary tokens. SOL is the native token of Solana, it conjointly offers associate SPL token customary that's rather like what the ERC20 token is for Ethereum. If an associate capitalist sends his SOL or SPL tokens to a wallet that doesn't support Solana, he can lose his tokens:
During Solana wallet development 3 most significant aspects are required to be taken into consideration:
A wallet address on the Solana blockchain could be a long string of base58 characters, which could be a quite common format within the crypto house. Generally, a Solana wallet address length varies between thirty-two to forty-four characters and appears one thing like this 3n2C45yBiNapKh6EdDekesZccAFdwTatu46Eyw1UnKx2
Seed phrase:
Whenever a user creates a brand new wallet, he has to produce a seed phrase or a security key. This seed phrase is mostly composed of twelve English keywords. Your wallet should prompt the user to avoid wasting this seed phrase in an exceedingly safe place because it is the sole manner he or she will restore their wallet if they lose access thereto. The seed phrase is totally different for each new wallet and appears one thing like this: moon estate subway tunnel helps internet army flash chime bitter fun internet lure.
A private key and a public key:
The non-public secret is associated alphameric key that's needed to attach to the wallet account. It helps the user determine their wallet on the network. A user desires a personal key to come up with a public key that may be shared with others. The format of a personal key is:
npLNkAEgTlnd78Q97G7y6PiwtBgGqKlPgoYjtkuoKsefFAbCocZBbK4vAtefP7BCgJVD9FbNa69UV1sKX8lmDFGY
We have to follow the following commands and libraries to connect Solana wallet:
We have web3.js Library to connect the Solana wallet
Installation (using node.js)
$ npm install --save @solana/web3.js ( Using npm installation)
or we can use a bundle to direct use of CDNs -
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.min.js"></script>
Usage
const solanaWeb3 = require("@solana/web3.js");
Connecting to a Wallet
To allow users to use your dApp or application on Solana, they will need to get access to their Keypair. A Keypair is a private key with a matching public key, used to sign transactions.
There are two ways to obtain a Keypair:
Generate a new Keypair
Obtain a Keypair using the secret key
You can obtain a new Keypair with the following:
const { Keypair } = require("@solana/web3.js");
let keypair = Keypair.generate();
This will generate a brand new Keypair for a user to fund and use within your application.
You can allow entry of the secretKey using a textbox, and obtain the Keypair with Keypair.fromSecretKey(secretKey).
const { Keypair } = require("@solana/web3.js");
let secretKey = Uint8Array.from([
202, 171, 192, 129, 150, 189, 204, 241, 142, 71, 205, 2, 81, 97, 2, 176, 48,
81, 45, 1, 96, 138, 220, 132, 231, 131, 120, 77, 66, 40, 97, 172, 91, 245, 84,
221, 157, 190, 9, 145, 176, 130, 25, 43, 72, 107, 190, 229, 75, 88, 191, 136,
7, 167, 109, 91, 170, 164, 186, 15, 142, 36, 12, 23,
]);
let keypair = Keypair.fromSecretKey(secretKey);
Many wallets nowadays enable users to bring their Keypair employing a kind of extension or net wallet. the overall recommendation is to use wallets, not Keypairs, to sign transactions. The wallet creates a layer of separation between the dApp and also the Keypair, guaranteeing that the dApp ne'er has access to the key. You'll notice ways in which to attach to external wallets with the wallet-adapter library.
November 21, 2024 at 11:17 am
Your comment is awaiting moderation.