npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@okxconnect/solana-provider

v1.5.2

Published

OKX Connect Solana Provider

Downloads

1,527

Readme

UI

In addition to the SDK, we also provide a UI interface. If you choose to integrate through the UI, and if the DApp is running inside Telegram, users can choose to stay within Telegram and invoke the mobile App wallet or the OKX Mini Wallet.

Installation and Initialization

Make sure to update the OKX App to version 6.90.1 or later to begin access:

To integrate OKX Connect into your DApp, you can use npm:

npm install @okxconnect/ui
npm install @okxconnect/solana-provider

Before connecting to a wallet, you need to create an object that can provide a UI interface for subsequent operations such as connecting to the wallet and sending transactions.

OKXUniversalConnectUI.init(dappMetaData, actionsConfiguration, uiPreferences, language)

Request parameters

  • dappMetaData - object
    • name - string: The name of the application, will not be used as a unique representation.
    • icon - string: URL of the application icon, must be in PNG, ICO, etc. SVG icons are not supported. SVG icons are not supported. It is best to pass a url pointing to a 180x180px PNG icon.
  • actionsConfiguration - object
    • modals - ('before' | 'success' | 'error')[] | 'all' The modes of displaying alerts during transaction, defaults to 'before'.
    • returnStrategy -string 'none' | ${string}://${string}; for app wallet, specify the return strategy for the deep link when the user signs/rejects the request, if it is in telegram, you can configure tg://resolve
    • tmaReturnUrl -string 'back' | 'none' | ${string}://${string}; For Telegram Mini Wallet, specify the return policy of deep link when user signs/rejects the request, if it's in telegram, you can configure tg://resolve none means no processing after signing; default is back;
  • uiPreferences -object
    • theme - Theme can be: THEME.DARK, THEME.LIGHT, 'SYSTEM'.
  • language - 'en_US' | 'ru_RU' | 'zh_CN' | 'ar_AE' | 'cs_CZ' | 'de_DE' | 'es_ES' | 'es_LAT' | 'fr_FR' | 'id_ID' | 'it_IT' | 'nl_NL' | 'pl_PL' | 'pt_BR' | 'pt_PT' | 'ro_RO' | 'tr_TR' | 'uk_UA' | 'vi_VN'. , defaults to en_US

Return value

  • OKXUniversalConnectUI

Example

import { OKXUniversalConnectUI } from "@okxconnect/ui";

const universalUi = await OKXUniversalConnectUI.init({
    dappMetaData: {
        icon: "https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png",
        name: "OKX Connect Demo"
    },
    actionsConfiguration: {
        returnStrategy: 'tg://resolve',
        modals:"all",
        tmaReturnUrl:'back'
    },
    language: "en_US",
    uiPreferences: {
        theme: THEME.LIGHT
    },
});

Connect to Wallet

Connecting to a wallet goes to get the wallet address as an identifier and the necessary parameters used to sign the transaction.

universalUi.openModal(connectParams: ConnectParams);

Request Parameters

  • connectParams - ConnectParams
    • namespaces - [namespace: string]: ConnectNamespace ; necessary information for the requested connection, the key is 'eip155' for EVM system and 'solana' for Solana system. If any of the requested chains are not supported by the wallet, the wallet will reject the connection;
      • chains: string[]; chain id information,
      • defaultChain?: string; default chain
    • optionalNamespaces - [namespace: string]: ConnectNamespace; optional information for requesting a connection, the key for for Solana is 'solana'. If the corresponding chain information is not supported by the wallet, the connection can still be made;
      • chains: string[]; Chain id information, chain information, chain information, chain information.
        • defaultChain?: string; defaultChain

Return Value

  • Promise<SessionTypes.Struct | undefined>
    • topic: string; session identifier;
    • namespaces: Record<string, Namespace>; namespace information for successful connections;
      • chains: string[]; Chain information for the connection;
      • accounts: string[]; accounts information for the connection;
      • methods: string[]; methods supported by the wallet under the current namespace;
      • defaultChain?: string; The default chain for the current session.
    • sessionConfig?: SessionConfig
      • dappInfo: object DApp information;
        • name:string
        • dappInfo: object DApp info; name:string

Example

var session = await universalUi.openModal({
    namespaces: {
        solana: {
            chains: ["solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", // solana mainnet
            //  "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",// solana testnet
            //  "sonic:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",// sonic testnet ;              
            ],
        }
    }
})

Determine if the wallet is connected

Gets whether the wallet is currently connected.

Return Value

  • boolean

Example

universalUi.connected();

Sending Signature and Transactions

Methods to send messages to the wallet, support signature, transaction.

First create an OKXSolanaProvider object, pass OKXUniversalProviderUI into the constructor, when calling OKXSolanaProvider related methods, the actionsConfiguration.mode configuration will be handled according to the values passed during init;

import { OKXSolanaProvider } from "@okxconnect/solana-provider";
let okxSolanaProvider = new OKXSolanaProvider(universalUi)

Signature

okxSolanaProvider.signMessage(message, chain);

Request parameters

  • message - string, the message to be signed
  • chain: string, the chain to be signed, it is recommended to pass this parameter; it is mandatory to pass this parameter when connecting multiple chains; if a chain is not passed, it will be handled according to solan:mainnet or sonic:testnet;

Return value

  • Promise - object
    • publicKey:string wallet address
    • signature:Uint8Array The signature result.

Sign a single transaction

okxSolanaProvider.signTransaction(transaction, chain)

request parameters

  • transaction - Transaction | VersionedTransaction transaction data object
  • chain: string, the chain for which the signature execution is requested, it is recommended to pass this parameter; it is mandatory to pass this parameter when connecting multiple chains; connecting a chain without passing it will be handled according to solan:mainnet or sonic:testnet;

Return Value

  • Promise - Transaction | VersionedTransaction signed transaction object.

Signs multiple transactions

okxSolanaProvider.signAllTransactions(transactions, chain);

request parameters

  • transactions - [Transaction | VersionedTransaction] array of transaction data objects
  • chain: string, the chain for which the signature execution is requested, it is recommended to pass this parameter; it is mandatory to pass this parameter when connecting multiple chains; connecting a chain without passing it will be handled according to solan:mainnet or sonic:testnet;

Return value

  • Promise - [Transaction | VersionedTransaction] An array of signed transaction objects.

Signs a transaction and broadcasts it for uploading

okxSolanaProvider.signAndSendTransaction(transaction, chain);

Request parameters

  • transactions - Transaction | VersionedTransaction transaction data object.
  • chain: string, request signature execution of the chain, it is recommended to pass this parameter; when connecting multiple chains is a mandatory parameter; connecting a chain if it is not passed, it will be processed according to solan:mainnet or sonic:testnet;

Return Value

  • Promise - string transactionhash.

get wallet address and pubKey

okxSolanaProvider.getAccount(chain);

Request parameters

  • chain: string, get the chain id of the wallet address, if not passed then the first connected svm address will be taken by default.

Return Value

  • Object
    • address: string wallet address
    • publicKey: public key

Example

//Signing a transfer transaction on solana mainnet
let provider = new OKXSolanaProvider(universalUi)
const transaction = new Transaction({
    feePayer: new PublicKey(provider.getAccount().address),
    recentBlockhash: "xNWbUfdEPktMsZQHY6Zk5RJqamWFcTKasekjr7c3wFX",
}).add(SystemProgram.transfer(
    {
        fromPubkey: new PublicKey(provider.getAccount().address),
        toPubkey: new PublicKey(provider.getAccount().address),
        lamports: 1000,
    }
))

let result = await provider.signTransaction(transaction, "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp")

Disconnect wallet

Disconnect the connected wallet and delete the current session. If you want to switch the connected wallet, please disconnect the current wallet first.

universalUi.disconnect();