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/ton-provider

v1.4.2

Published

OKX Connect TON Provider

Downloads

7

Readme

SUI

Sui 又称 Sui Network,是第一个从零开始设计,且能够使开发者为十亿 Web3 新用户构建全新体验的 Layer 1 区块链。Sui 可横向扩展,能够高速且低成本地支持多样的 DApp 开发。Sui 开创了通用区块链的先河,为用户带来高吞吐量、超快结算速度、丰富的链上资产、以及用户友好的 Web3 体验。Sui 是区块链技术的一个跨越式的进步,从底层开始设计,以满足加密货币中所有相关方的需求。

安装及初始化

请确保更新OKX App到 6.90.1版本或以后版本,即可开始接入:

将 OKX Connect 集成到您的 DApp 中,可以使用 npm:

npm install @okxconnect/sui-provider

连接钱包之前,需要先创建一个对象,用于后续连接钱包、发送交易等操作。

OKXUniversalProvider.init({metaData: {name, icon}})

请求参数

  • metaData - object
    • name - string: 应用名称,不会作为唯一表示
    • icon - string: 应用图标的 URL。必须是 PNG、ICO 等格式,不支持 SVG 图标。最好传递指向 180x180px PNG 图标的 url。

返回值

  • OKXUniversalProvider

示例

import { OKXUniversalProvider } from "@okxconnect/universal-provider"
const okxUniversalProvider = OKXUniversalProvider.init({dappMetaData: {
        name: "application name",
        icon: "application icon url"
    }})

连接钱包

连接钱包去获取钱包地址,作为标识符和用于签名交易的必要参数。

okxUniversalProvider.connect(connectParams: ConnectParams);

请求参数

  • connectParams - ConnectParams
    • namespaces - [namespace: string]: ConnectNamespace ; 请求连接的必要信息,Sui系的key为"sui" ,如果请求的链中,有任何一个链钱包不支持的话,钱包会拒绝连接;
      • chains: string[]; 链id信息,
    • optionalNamespaces - [namespace: string]: ConnectNamespace; 请求连接的可选信息, EVM系的key为"eip155",Sui系的key为"sui" ,如果对应的链信息钱包不支持,依然可以连接;
      • chains: string[]; 链id信息,
    • sessionConfig: object
      • redirect: string 连接成功后的跳转参数,如果是Telegram中的Mini App,这里可以设置为Telegram的deeplink: "tg://resolve"

返回值

  • Promise<SessionTypes.Struct | undefined>
    • topic: string; 会话标识;
    • namespaces: Record<string, Namespace>; 成功连接的namespace 信息;
      • chains: string[]; 连接的链信息;
      • accounts: string[]; 连接的账户信息;
      • methods: string[]; 当前namespace下,钱包支持的方法;
      • rpcMap?: [chainId: string]: string; rpc 信息;
      • defaultChain?: string; 当前会话的默认链
    • sessionConfig?: SessionConfig
      • dappInfo: object DApp 信息;
        • name:string
        • icon:string
      • redirect?:string, 连接成功后的跳转参数;

示例

var session = await okxUniversalProvider.connect({
    namespaces: {
        sui: {
            chains: ["sui:mainnet"]
        }
    },
    sessionConfig: {
        redirect: "tg://resolve"
    }
})

断开连接

断开已连接钱包,并删除当前会话,如果要切换连接钱包,请先断开当前钱包。

示例

okxUniversalProvider.disconnect();

发送签名和交易

向钱包发送消息的方法,支持签名,交易,rpc请求。

首先创建一个OKXSuiProvider对象,构造函数传入OKXUniversalProvider

import { OKXSuiProvider } from "@okxconnect/sui-provider"
let suiProvider = new OKXSuiProvider(okxUniversalProvider)

签名Message

suiProvider.signMessage(input: SuiSignMessageInput);

请求参数

  • SuiSignMessageInput - object
    • message: Uint8Array

返回值

  • Promise - object
    • messageBytes: string
    • signature: string

签名PersonalMessage

suiProvider.signPersonalMessage(input: SuiSignMessageInput);

请求参数

  • SuiSignMessageInput - object
    • message: Uint8Array

返回值

  • Promise - object
    • bytes: string
    • signature: string

示例

const data = [76, 111, 103, 105, 110, 32, 119, 105, 116, 104, 32, 66, 108, 117, 101, 109, 111, 118, 101];
const uint8Array = new Uint8Array(data);
let input = {
    message: uint8Array
}
let signResult1 = await suiProvider.signMessage(input)
let signResult2 = await suiProvider.signPersonalMessage(input)

签交易

suiProvider.signTransaction(input);

请求参数

// txBytes与txSerialize为transactionBlock的序列化
// 和transactionBlock传入一种即可无需同时传入
interface SuiSignTransactionBlockInput {
    transactionBlock: TransactionBlock;
    chain: IdentifierString;
    txBytes: string?;
    txSerialize: string?
}

返回值

  • Promise - object
    • signature: string,
    • transactionBlockBytes: string

签一笔交易并广播上链

suiProvider.signAndExecuteTransaction(input);

请求参数

// txBytes与txSerialize为transactionBlock的序列化
// 和transactionBlock传入一种即可无需同时传入
interface SuiSignTransactionBlockInput {
    transactionBlock: TransactionBlock;
    chain: IdentifierString;
    txBytes: string?;
    txSerialize: string?;
}

返回值

  • Promise - object
    • confirmedLocalExecution: bool,
    • digest: string,
    • txBytes: string

示例

// 定义要转移的金额和目标地址
const amount = 109; // 需要转移的金额
const recipientAddress = '0x'; // 目标地址

/// 构造一个转账的交易
const tx = new Transaction();
const [coin] = tx.splitCoins(tx.gas, [amount]);
tx.transferObjects([coin], recipientAddress)
const input = {
    transactionBlock: tx,
    chain: 'sui:mainnet',
    options: {
        showEffects: true,
    }
}

let signResult1 = await suiProvider.signTransaction(input)
let signResult2 = await suiProvider.signAndExecuteTransaction(input)