Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aldea/wallet-lib

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aldea/wallet-lib

High level and versatile wallet tool for Aldea Blockchain

  • 0.3.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Wallet How-To

These are the basics on how to use the wallet.

Step 1: Choose your storage

We have 2 types of storage at the moment: LowDB and memory. Low db allows you to use several supports:

import { Memory } from "lowdb"
import { JSONFile, TextFile } from "lowdb/node"
import { LowDbStorage, LowDbData } from "@aldea/wallet-lib"

// lowdb + memory
const storage = new LowDbStorage(new Memory<LowDbData>())
// lowdb + jsonfile
const storage = new LowDbStorage(new JSONFile<LowDbData>('path/to/my/json/file.json'))
// lowdb + textfile
const storage = new LowDbStorage(new JSONFile<LowDbData>('path/to/my/file.txt'))

And memory (transient storage):

import { LowDbStorage, MemoryStorage } from "@aldea/wallet-lib"

const storage = new MemoryStorage()

Step 2: Create a wallet instance

Again, 2 options: Single key wallet and HDWallet

import { SingleKeyWallet, HdWallet } from "@aldea/wallet-lib"
import { Aldea, HDPrivKey, PrivKey } from "@aldea/sdk"

const pk = PrivKey.fromRandom()
const aldea = new Aldea()
const wallet1 = new SingleKeyWallet(pk, aldea, storage)
const wallet2 = new HdWallet(storage, aldea, hdPriv)

Step 3: Mint some coins

const kyResponse = await aldea.api.post('mint', { 
  headers: { 
    'Content-Type': 'application/json' 
  }, 
  body: JSON.stringify({ 
    address: await wallet.getNextAddress().then(a => a.toString()), 
    amount: 500 
  })
})

const output = Output.fromJson(await kyResponse.json())
await wallet.addUtxo(output)

Step 4: Do some txs

There is a wraper around aldea.createTx that signs, fund and broadcast

const response = await wallet.fundSignAndBroadcastTx(async builder => {
  const pkgIdx = builder.import('ea9225bcf8572c3a9fa75d186b62ab976d017d96b0614612f59d5fa5087b7fa3')
  const nftIdx = builder.new(pkgIdx, 'NFT', ['name', 32, 'moreName'])
  builder.lock(nftIdx, await wallet.getNextAddress())
})

Another option is doing this by hand:

const tx = aldea.createTx(async builder => {
  const pkgIdx = builder.import('ea9225bcf8572c3a9fa75d186b62ab976d017d96b0614612f59d5fa5087b7fa3')
  const nftIdx = builder.new(pkgIdx, 'NFT', ['name', 32, 'moreName'])
  builder.lock(nftIdx, await wallet.getNextAddress())
  await wallet.fundTx(builder)
  await wallet.signTx(builder)
})

const commitResponse = await aldea.commitTX(tx)
await wallet.processTx(tx, commitResponse.output.map(Output.fromJson))

Step 5: Viewing Your Balance

const utxos = wallet.getInventory()
const coins = utxos.filter(u => u.classPtr.id === new Array(32).fill(0).join(''))

FAQs

Package last updated on 17 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc