Lnfi Network (Formerly NostrAssets)
  • β­•Overview
    • πŸ”°Key Features
    • πŸ€–Technology
  • ❓How does it work
  • πŸ”°Receive & Send Assets
  • πŸ”…Transfer Nostr Assets
  • ✨Importing Assets
  • πŸ”ŽPublicly Viewable Data
  • ⏩Nostr Assets Commands
  • 🟒Marketplace
    • Marketplace Commands
  • ⚑Lightning Starter: Transparent Unbiased Fair Mint
    • Phase 1 Rules
    • Phase 2 Rules
    • Phase 3 Rules
  • 🎁Lightning Gift
  • πŸ”“Lock Assets
  • 🌟MicroNode (Early Access)
    • MicroNode User Guide (Early Access)
    • MicroNode Connect (MNC)
    • MicroNode Disclaimer
  • πŸ”—Official Links
  • ⚠️Disclaimer
  • πŸ—ΊοΈRoadmap & Progress
  • User Guides (Updated Nov 2023)
    • Desktop Users
    • Desktop Chat-to-Trade
    • Mobile Chat-to-Trade
    • Token Pocket Users
      • How to get your new Nostr account in Token Pocket
      • Marketplace Setup (Token Pocket)
      • How to use Marketplace? (Token Pocket)
    • OKX Wallet
    • OneKey
  • NostrAssets SDK & API
    • API
    • SDK
Powered by GitBook
On this page
  • NASDK SDK Guide
  • Introduction
  • Features
  • Support Method List
  • nasdk
  • nasdk.market
  • nasdk.token
  • nasdk.provider
  • Setup
  • React
  • Node.js
  • Example
  • Running Tests
  1. NostrAssets SDK & API

SDK

PreviousAPI

Last updated 1 year ago

NASDK SDK Guide

Link to Github:

Introduction

Welcome to the NASDK (Nostr Asset SDK) guide! NASDK is an SDK library developed based on the NOSTR ASSET protocol. It facilitates connecting plugin wallets supporting NOSTR, executing transactions, and managing orders seamlessly.

Features

  • Connect plugin wallets supporting NOSTR

  • Execute transactions

  • Place orders in the market


Support Method List

nasdk

  • getConfig(): Retrieve configuration.

  • getNostrPool(): Get information about the Nostr pool.

nasdk.market

  • listOrder(options): List orders in the market.

  • takeOrder(orderId): Take an order in the market.

  • cancelOrder(orderId): Cancel an order in the market.

  • repairOrder(orderId, amount, price, buyOrSellTokenName, payTokenName): Repair an order in the market.

nasdk.token

  • approve(options): Approve token transfer.

  • transfer(options): Transfer tokens.

  • addAddressBook(options): Add an address to the address book.

  • deposit(options): Deposit tokens.

  • withdraw(options): Withdraw tokens.

nasdk.provider

  • supportedProviderList: Retrieve a list of supported providers.

  • connect(providerName): Connect to a provider.

  • getProvider(providerName): Get information about a provider.

nasdk.utils

  • nip04(): NIP04 utilities.

  • nip19(): NIP19 utilities.

  • generatePrivateKey(): Generate a private key.

  • getPublicKey(privateKey): Get a public key from a private key.

  • getEventHash(event): Get the hash of an event.


Setup

React

Install

yarn add nasdk

//import bolt11min.js to public/index.html through script src
<script src=`${yourpath}/bolt11.min.js``></script>

Code

import {useCallback} from 'react
import NASDK from 'nasdk'
const nasdk = new NASDK({ env: 'development'}) // env: development | production
const onTransfer = useCallback(async()=>{
    const res = await nasdk.token.transfer({ tokenName: 'NOSTR', amount: 1, to: 'npub1zptcf2v9ms5dgd8mgulsckk04l9upr3lnerk6ckh9zyntzu0ness753zx8' })
},[])
return <>
{your code}
</>


Node.js

Installation

yarn add websocket-polyfill bolt11 nasdk

Code

import 'websocket-polyfill'
import 'bolt11'
import NASDK from 'nasdk'

const privateKey='45d914aef9c2f85a47b242ef684245c02e0af93d6f9031fcc3444ede8ac0a295'
const nasdk = new NASDK({ env: 'development', privateKey, poolOptions:{getTimeout:10*1000} })

 const res = await nasdk.market.listOrder({ side:'sell',amount:'100',price:'101',buyOrSellTokenName:'TRICK',payTokenName:'SATS'})

 // You can see more examples in the tests directory

HTML

<scrpt src=`${youpath}/nasdk.umd.js`>
<script src=`${yourpath}/bolt11.min.js``></script>
<script>
     const nasdk = new NASDK({ env: 'development' })
     const supportedProviderNames = Object.keys(nasdk.provider.supportedProviderList)
     async function onConnect(providerName='alby') {
        const res = await nasdk.provider.connect(providerName)
     }
</script>

Example

Check out examples in the src/tests directory.

Running Tests

To run the test suite:

yarn node --experimental-vm-modules $(yarn bin jest) --detectOpenHandles

Start integrating NASDK into your project and unlock the potential of the NOSTR ASSET protocol!

https://github.com/nostrassets/nasdk