
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@project-serum/sol-wallet-adapter
Advanced tools
Library to allow Solana dApps to use third-party wallets to sign transactions
Library to allow Solana dApps to use third-party wallets to sign transactions.
npm install --save @project-serum/sol-wallet-adapter
import { Connection, SystemProgram, Transaction, clusterApiUrl } from '@solana/web3.js';
let connection = new Connection(clusterApiUrl('devnet'));
let providerUrl = 'https://www.sollet.io';
let wallet = new Wallet(providerUrl);
wallet.on('connect', publicKey => console.log('Connected to ' + publicKey.toBase58()));
wallet.on('disconnect', () => console.log('Disconnected'));
await wallet.connect();
let transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: wallet.publicKey,
toPubkey: wallet.publicKey,
lamports: 100,
})
);
let { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = wallet.publicKey;
let signed = await wallet.signTransaction(transaction);
let txid = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(txid);
See example/src/App.js for a full example.
const providerUrl = 'https://www.sollet.io';
const wallet = new Wallet(providerUrl);
wallet.on('connect', publicKey => console.log('Connected to ' + publicKey.toBase58()));
wallet.on('disconnect', () => console.log('Disconnected'));
await wallet.connect();
const message = "Please sign this message for proof of address ownership.";
const data = new TextEncoder().encode(message);
let { signature } = await wallet.sign(data, 'utf8');
Run yarn start in the root directory, then run yarn start in the example directory.
See create-react-library for details.
Wallet providers are third-party webapps that provide an API to retrieve the user's accounts and sign transactions with it. sol-wallet-adapter opens wallet providers in a popup and communicates with it using JSON-RPC over postMessage.
See spl-token-wallet for an example wallet provider implementation.
The general flow is as follows:
https://www.sollet.iohttps://www.sollet.io/#origin=https://www.example.com&network=mainnet-betawindow.opener is set and asks the user if they want to connect the wallet to the dApp.
new URLSearchParams(window.location.hash.slice(1)).get('origin').connected message to the dApp via postMessage.
window.opener.postMessage({jsonrpc: '2.0', method: 'connected', params: {publicKey: 'EdWqEgu54Zezi4E6L72RxAMPr5SWAyt2vpZWgvPYQTLh'}}, 'https://www.example.com')'postMessage call must set targetOrigin to the dApp origin that was shown to the user in step 3.signTransaction request using postMessage.
window.onmessage events.event.origin matches the dApp origin and event.source === window.opener.Wallet provider developers can use the example webapp to test their implementation.
origin - origin of the dApp. Should be included in all postMessage calls and should be checked against all received MessageEvents.network - The network on which transactions will be sent. Can be any of mainnet-beta, devnet, testnet, or a custom URL, though wallets are free to reject any unsupported networks. Wallet providers should check that transaction blockhashes matches the network before signing the transaction.The parameters can be parsed using
let params = new URLSearchParams(window.location.hash.slice(1));
let origin = params.get('origin');
let network = params.get('network');
sol-wallet-adapter)Sent by the wallet provider when the user selects an account to connect to the dApp.
publicKey - Base-58 encoded public key of the selected account.window.opener.postMessage({
jsonrpc: '2.0',
method: 'connected',
params: {
publicKey: 'HsQhg1k93vEA326SXxnGj1sZrdupG7rj5T6g5cMgk1ed',
},
}, origin);
Sent by the wallet provider when the user no longer wishes to connect to the dApp, or if the user closes the popup (onbeforeunload).
None.
window.opener.postMessage({
jsonrpc: '2.0',
method: 'disconnected',
}, origin);
sol-wallet-adapter) to the wallet providerSent by the dApp when it needs to send a transaction on behalf of the user.
message - Base-58 encoded transaction message for the wallet to sign. Generated by transaction.serializeMessage().signature - Base-58 encoded transaction signature, i.e. bs58.encode(nacl.sign.detached(message, account.secretKey)).publicKey - Base-58 encoded public key of the account that provided the signature.let request = {
jsonrpc: '2.0',
method: 'signTransaction',
params: {
message: "QwE1mEmQpjGKTQz9U3N8xTJCqCry9kgvJff51kVv8h5AyVGh3L…NfV68ERMb2WsVAstN',
},
id: 1,
};
let response = {
jsonrpc: '2.0',
result: {
signature: "2HT61qv1xxWUpx7DXZM3K878wU1JJx5eKNWw64cgeauwx6sZNKtDkSRrGvqZmsRwz6c1RwkUFnPj1LXkjNtsCd9o",
publicKey: 'HsQhg1k93vEA326SXxnGj1sZrdupG7rj5T6g5cMgk1ed'
},
id: 1,
};
FAQs
Library to allow Solana dApps to use third-party wallets to sign transactions
The npm package @project-serum/sol-wallet-adapter receives a total of 94,790 weekly downloads. As such, @project-serum/sol-wallet-adapter popularity was classified as popular.
We found that @project-serum/sol-wallet-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.