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

@okxweb3/coin-stellar

v1.0.0-beta.1

Published

Stellar SDK is used to interact with the Stellar blockchain and PI blockchains, it contains various functions can be used to web3 wallet.

Downloads

15

Readme

@okxweb3/coin-stellar

Stellar SDK is used to interact with the Stellar blockchain and PI blockchains, it contains various functions can be used to web3 wallet.

Installation

Npm

To obtain the latest version, simply require the project using npm :

npm install @okxweb3/coin-stellar

Usage

Generate Private Key

import { StellarWallet } from "@okxweb3/coin-stellar"

let wallet = new StellarWallet();
// get random key
let randomPrivateKey = await wallet.getRandomPrivateKey();

Private Key Derivation

import { StellarWallet } from "@okxweb3/coin-stellar"

let wallet = new StellarWallet();
let mnemonic = "stool trumpet fame umbrella bench provide battle toward story fruit lock view"
let param = {
  mnemonic: mnemonic,
  hdPath: "m/44'/148'/0'" //stellar,if PI, please use m/44'/314159'/0' and PIWallet
};

let privateKey = await wallet.getDerivedPrivateKey(param)

Generate Address

import { StellarWallet } from "@okxweb3/coin-stellar"

let wallet = new StellarWallet();
let params = {
    privateKey: 'SAGYHCI53Z3QG2TGYUIF24BJEKTZSPSQPQ7OW2WULSSTZXJ426THA4GW'
}
let newAddress = await wallet.getNewAddress(params);

Verify Address

import { StellarWallet } from "@okxweb3/coin-stellar"

let wallet = new StellarWallet();
let params = {
    address: "GBL7IXVKK7UKX6YZB5AA3QB5H47SFNM6RNSXT6WNWH6R36NFYHDR5OBA"
};
let valid = await wallet.validAddress({address:addr.address});

Sending a Transaction

Use the signTransaction function to get the signed tx to broadcast

Example

  1. createAccount
 let sourceSecret ="SCPVS2UMH4EPBAZPEQXGSC7OMNJTTS5STD7EIDL4OEJW2HYHES7DNUJ4";
let sourceAddress = await wallet.getNewAddress({privateKey:sourceSecret});
console.log(sourceAddress)

let addr = await wallet.getNewAddress({privateKey:"SAGYHCI53Z3QG2TGYUIF24BJEKTZSPSQPQ7OW2WULSSTZXJ426THA4GW"});
addr = await wallet.getNewAddress({privateKey:"SACXX2WZKGFELPK6ZFXUYMWSABVVTPBDUFUB44FEBNG32J45HBSJ5JPW"});
console.log(addr)

let sourceAccount = new Account(sourceAddress.address,"2077119198789642");
let op = Operation.createAccount({
    destination: addr.address,
    startingBalance: "1",
});
let tx = await wallet.signTransaction({
    privateKey:sourceSecret,
    data:{
        source: sourceAccount,
        fee: "100",
        networkPassphrase: Networks.TESTNET,
        operations:[op]
    },
});
console.log(tx)
  1. transfer native asset
let wallet = new StellarWallet();
let sourceSecret ="SCPVS2UMH4EPBAZPEQXGSC7OMNJTTS5STD7EIDL4OEJW2HYHES7DNUJ4";
let sourceAddress = await wallet.getNewAddress({privateKey:sourceSecret});
console.log(sourceAddress)

let addr = await wallet.getNewAddress({privateKey:"SAGYHCI53Z3QG2TGYUIF24BJEKTZSPSQPQ7OW2WULSSTZXJ426THA4GW"});
console.log(addr)

let sourceAccount = new Account(sourceAddress.address,"2077119198789635");
let op = Operation.payment({
    destination: addr.address,
    asset: Asset.native(),
    amount: "1",
});
let tx = await wallet.signTransaction({
    privateKey:sourceSecret,
    data:{
        source: sourceAccount,
        fee: "100",
        networkPassphrase: Networks.TESTNET,
        operations:[op],
    },
});
  1. create trusline
let wallet = new StellarWallet();
let sourceSecret ="SCPVS2UMH4EPBAZPEQXGSC7OMNJTTS5STD7EIDL4OEJW2HYHES7DNUJ4";
let sourceAddress = await wallet.getNewAddress({privateKey:sourceSecret});
//GBABZSCZ4NRIXUXDPQLLX5PUOEUUTHT5KFF4DS447GRJXDBWA32ZOJFW
console.log("sourceAddress:",sourceAddress)

let userSecret = "SAGYHCI53Z3QG2TGYUIF24BJEKTZSPSQPQ7OW2WULSSTZXJ426THA4GW";
let addr = await wallet.getNewAddress({privateKey:userSecret});
//GBL7IXVKK7UKX6YZB5AA3QB5H47SFNM6RNSXT6WNWH6R36NFYHDR5OBA
console.log("addr:",addr)
let userAccount = new Account(addr.address,"2085700543447040");

let sourceAccount = new Account(sourceAddress.address,"2077119198789637");
const asset = new Asset('USD', sourceAddress.address);

//创建trustline
let op = Operation.changeTrust({
    asset: asset,
    limit: "1000",
});
let tx = await wallet.signTransaction({
    privateKey:userSecret,
    data:{
        source: userAccount,
        fee: "100",
        networkPassphrase: Networks.TESTNET,
        operations:[op],
        memo:Memo.id("1"),
    },
});
console.log("tx:", tx);
  1. transfer non-native asset
let wallet = new StellarWallet();
let sourceSecret ="SCPVS2UMH4EPBAZPEQXGSC7OMNJTTS5STD7EIDL4OEJW2HYHES7DNUJ4";
let sourceAddress = await wallet.getNewAddress({privateKey:sourceSecret});

let userSecret = "SAGYHCI53Z3QG2TGYUIF24BJEKTZSPSQPQ7OW2WULSSTZXJ426THA4GW";
let addr = await wallet.getNewAddress({privateKey:userSecret});
let userAccount = new Account(addr.address,"2085700543447040");

let sourceAccount = new Account(sourceAddress.address,"2077119198789637");
const asset = new Asset('USD', sourceAddress.address);

let op = Operation.payment({
    destination:addr.address,
    asset: asset,
    amount: "100",
});
let tx = await wallet.signTransaction({
    privateKey:sourceSecret,
    data:{
        source: sourceAccount,
        fee: "100",
        networkPassphrase: Networks.TESTNET,
        operations:[op],
        memo:Memo.id("1"),
    },
});

Input Params

export type StellarTxParam = {
    source: string, // sourceAccount address
    operations: [], // createAccount, Payment, PathPayment...
    fee: string; //basefee,1000000
    memo?: Memo; 
    networkPassphrase?: string;
    timebounds?: { //time limit,  
        minTime?: Date | number | string; 
        maxTime?: Date | number | string;
    };
    ledgerbounds?: {
        minLedger?: number;
        maxLedger?: number;
    };
    minAccountSequence?: string;
    minAccountSequenceAge?: number;
    minAccountSequenceLedgerGap?: number;
    extraSigners?: string[];
}

License

MPL-2.0