# Solana
Note
You can use third-party libraries in conjunction with window.safepal
# Installed or not
const isSafePalInstalled = window.isSafePal;
1
https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets
# Provider
function getProvider() {
const provider = window.safepal;
if (!provider) {
return window.open('https://www.safepal.com/download?product=2');
throw `Please guide users to download from our official website`
}
return provider;
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# connect(request authorization to connect)
try {
await window.safepal.connect();
const publicKey = await window.safepal.getAccount();
window.safepal.publicKey.toString(); // Once the web application is connected to SafePal,
} catch {
alert('connected error');
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# connected
window.safepal.connected;
const publicKey = await window.safepal.getAccount();
window.safepal.publicKey.toString(); // Once the web application is connected to SafePal
1
2
3
2
3
# signMessage
//string
window.safepal.signMessage(
'020006106e655af38ff7324bbf1d4e16b06084763269b9'
);
// uint8Array
const message = `You can use uint8array to verify`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await window.safepal.signMessage(encodedMessage);
const nacl = require('tweetnacl');
const { PublicKey } = require('@solana/web3.js');
// nacl.sign.detached.verify(encodedMessage, signedMessage, publicKey)
nacl.sign.detached.verify(
encodedMessage,
signedMessage,
new PublicKey(address).toBytes()
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Event listeners
used eventemitter3 (opens new window)
window.safepal.on('connect', () => console.log('connected!'));
1
# sendTransaction
You can refer to the following demo : simple demo (opens new window) web3 demo (opens new window) Token demo (opens new window)
← Ethereum(EVM) Tron →