# Solana

提示

使用第三方库时,使用 window.bitkeep.solana 作为程序的提供者。

# 是否安装

const isBitKeepInstalled = window.isBitKeep && window.bitkeep.solana;
1

https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets (opens new window)

# 提供者

function getProvider() {
  const provider = window.bitkeep && window.bitkeep.solana;
  if (!provider) {
    window.open('https://bitkeep.com/en/download?type=2');
    throw  `Please guide users to download from our official website`
  }
  return provider;
}
1
2
3
4
5
6
7
8

# connect

请求授权连接

try {
  await window.bitkeep.solana.connect();
  const publicKey = await window.bitkeep.solana.getAccount();
  window.bitkeep.solana.publicKey.toString(); // Once the web application is connected to Bitkeep,
} catch {
  alert('connected error');
}
1
2
3
4
5
6
7

# connected

window.bitkeep.solana.connected;
const publicKey = await window.bitkeep.solana.getAccount();
window.bitkeep.solana.publicKey.toString(); // Once the web application is connected to Bitkeep
1
2
3

# signMessage

//string
window.bitkeep.solana.signMessage(
  '020006106e655af38ff7324bbf1d4e16b06084763269b9'
);
// uint8Array
const message = `You can use uint8array to verify`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await window.bitkeep.solana.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

# 事件监听器

使用 eventemitter3 (opens new window)

window.bitkeep.solana.on('connect', () => console.log('connected!'));
1

# sendTransaction

你可以参考下列演示: