@streambird/solana-embed-sdk
v1.0.4
Published
## Example
Downloads
4
Readme
@streambird/solana-embed-sdk
Example
import React from 'react';
import Streambird from '../';
import { PublicKey, Transaction, Connection, clusterApiUrl } from '@solana/web3.js';
var streambird = null;
function App() {
useEffect(() => {
streambird = new Streambird();
streambird.on('connect', handleConnected);
const checkReconnect = async () => {
if(!connected) {
await streambird.init();
}
}
checkReconnect();
}, []);
const handleConnected = async (publicKey) => {
let connection = new Connection(clusterApiUrl(network), 'confirmed');
const samplePublicKey = new PublicKey(publicKey);
let balance = await connection.getBalance(samplePublicKey);
}
const handleConnect = async () => {
try {
await streambird.init();
await streambird.login();
} catch (e) {
console.log(e);
}
};
const handleDisconnect = async () => {
streambird.cleanUp();
}
const handleSignTransaction = async () => {
try {
const transaction = await streambird.signTransaction(await createTransaction());
setOutputData(JSON.stringify(transaction));
setIsSendTransaction(false);
} catch(e) {
console.log(e);
}
};
}
API
class Streambird extends EventEmitter {
isInitialized: boolean;
constructor(config?: StreambirdParams);
get publicKey(): PublicKey | null;
get isConnected(): boolean | undefined;
get connected(): boolean | undefined;
get isLoggedIn(): boolean | null;
init({ publicToken, apiHost }?: StreambirdParams): Promise<void>;
login(): Promise<string>;
disconnect(): Promise<void>;
logout(): Promise<void>;
cleanUp(): Promise<void>;
clearIframe(): void;
signMessage(data: Uint8Array): Promise<Uint8Array>;
signTransaction(transaction: Transaction): Promise<Transaction>;
signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
sendTransaction(transaction: Transaction): Promise<Transaction>;
}
Run Example App
- Update
example/App.js
to use your own public api token. - In the root directory, run
yarn install
yarn build
yarn example:start