GithubHelp home page GithubHelp logo

ava-labs / avalanche-wallet-sdk Goto Github PK

View Code? Open in Web Editor NEW
40.0 26.0 26.0 4.16 MB

A Typescript library to create and manage wallets on the Avalanche network.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 0.77% Shell 0.01% TypeScript 99.22%

avalanche-wallet-sdk's Introduction

🔴WARNING: Beta Release🔴

  • This library is under development and there might be frequent breaking changes.
  • Audit pending.

Avalanche Wallet SDK (Beta)

Avalanche Wallet SDK is a Typescript library for creating and managing decentralized wallets.

It provides high level methods to transact on Avalanche's primary networks: X, P and C chain.

Wallet types supported:

  • Singleton Wallets
  • Ledger Wallets
  • Mnemonic Wallets
  • Public Mnemonic Wallets (XPUB)

Using the avalanche-wallet-sdk developers can:

  • Receive and send tokens and NFTs.
  • Cross chain transfer
  • Validation & Delegation
  • Create keystore files from wallet instances
  • Get transaction history of wallets
  • Mint NFTs on the X chain

Installation

With npm

npm install --save @avalabs/avalanche-wallet-sdk

or yarn

yarn add @avalabs/avalanche-wallet-sdk

Local build

  1. Clone the repository.
  2. Install dependencies yarn install
  3. Run for development yarn start

Webpack

For Webpack version 5 and above you must use this plugin with it. https://www.npmjs.com/package/node-polyfill-webpack-plugin

Docs

Can generate documentation with yarn docs and open docs/index.html in a browser.

avalanche-wallet-sdk's People

Contributors

connorch avatar dependabot[bot] avatar dfenstermaker avatar dhrubabasu avatar gergelylovas avatar iknowhtml avatar kanatliemre avatar nahoc avatar paool avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avalanche-wallet-sdk's Issues

Enchancement: "Nothing to import" throws Error but maybe it should not

When doing importP etc... it throws Error, but it's merely normal situation not Error condition.
If you want to check that nothing is left accidentally not imported you cannot call Promise.all([multiple imports because it throws Error])

:"Nothing to import.","stack":"Error: Nothing to import.\n at SingletonWallet.<anon...

Wallet.updateBalanceX()

I would like to update the X-chain balance of a wallet so that I can access the wallet's balance of various ANT tokens. Since updateBalanceX() is private, the only way to do this seems to be calling updateUtxosX(). However, this function calls updateBalanceX() without awaiting its promise, so I'm not sure how I can tell when it has finished updating the X-chain balance. For my use case, I would prefer if the function did the following:

await this.updateUnknownAssetsX();
await this.updateBalanceX();

I understand that the function is probably written as it currently is because updateBalanceX() is a costly function. Maybe a solution could be to have a boolean parameter waitForBalance for the function updateBalanceX() with the following code:

if (waitForBalance) {
    await this.updateBalanceX();
else {
    this.updateBalanceX();
}

Apologies in advance if there is another solution to this issue that I'm missing.

MnemonicWallet should support bip39 passphrase

Currently it's only possible to instantiate a MnemonicWallet with a seed phrase. For users that have a bip39 passphrase associated with the mnemonic, the constructor should support an optional passphrase field.

avalanche in devDependancies

Putting avalanche in devDependancies is not installing this lib with yarn and as a result, the app fails to build. The workaround will be to add avalanche to the app package. Was this intended?

Error Package subpath

I am getting an error when I run yarn install. It says that package.json is not defined by "exports". The error I am getting is below, when I click the link it takes me to the package.json file.

[!] Error: Package subpath './package.json' is not defined by "exports" in /Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/node_modules/tslib/package.json

node-fetch should ship with the non browser version

When attempting to run a terminal based app using version 0.17.2, I get this error:

/@avalabs/avalanche-wallet-sdk/dist/index.js:1596
            const response = yield fetch(input, Object.assign(Object.assign({}, options), { signal: controller.signal }));
                             ^

ReferenceError: fetch is not defined
    at HttpClient.<anonymous> (/@avalabs/avalanche-wallet-sdk/dist/index.js:1596:30)
    at Generator.next (<anonymous>)
    at /@avalabs/avalanche-wallet-sdk/dist/index.js:186:71
    at new Promise (<anonymous>)
    at __awaiter (/@avalabs/avalanche-wallet-sdk/dist/index.js:182:12)
    at HttpClient.fetchWithTimeout (/@avalabs/avalanche-wallet-sdk/dist/index.js:1592:16)
    at HttpClient.post (/@avalabs/avalanche-wallet-sdk/dist/index.js:1576:41)
    at /@avalabs/avalanche-wallet-sdk/dist/index.js:5450:46
    at Generator.next (<anonymous>)
    at /@avalabs/avalanche-wallet-sdk/dist/index.js:186:71
    at new Promise (<anonymous>)
    at __awaiter (/@avalabs/avalanche-wallet-sdk/dist/index.js:182:12)
    at getAddressChains (/@avalabs/avalanche-wallet-sdk/dist/index.js:5441:12)
    at HdScanner.<anonymous> (/@avalabs/avalanche-wallet-sdk/dist/index.js:7347:36)
    at Generator.next (<anonymous>)
    at fulfilled (/@avalabs/avalanche-wallet-sdk/dist/index.js:183:58)

A working solution is to install the CJS module via:

npm install node-fetch@2
Then edit @avalabs/avalanche-wallet-sdk/dist/index.js and add

const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
at the top of the file.

Perhaps node-fetch should be included in the node only version?

Cant Send Avax(C)

ReferenceError: fetch is not defined
Ive installed the fetch package and my IDE allows me to scope definition

also event listeners arent working aswell

MaxListenersExceededWarning in walletadapter

Hi the following code was not properly clearing EventEmitter events causing MaxListenersExceededWarning.
wallet.ts line 150
public destroy() {
networkEvents.off('network_change', this.onNetworkChange);
}

I was able to resolve the waring using
networkEvents.removeAllListeners('network_change');
or
networkEvents.removeAllListeners();

I am not familiar with EventEmitter so I just wanted to mainly report the issue.

Wallet.d.ts has different version in npm than here in repository

Version 0.10.1 typescript in npm seems to still have importC without parameters
but the code has already importC(chained) version...

Wallet.d.ts ....

`/**
 * Imports atomic X chain utxos to the current actie X chain address
 * @param chainID The chain ID to import from, either `P` or `C`
 */
importX(chainID: AvmImportChainType): Promise<string>;
importP(toAddress?: string): Promise<string>;
importC(): Promise<string>;`

Conflicting Peer dependency with Avalanche

I am trying to use both "avalanche": "3.15.5" and "@avalabs/avalanche-wallet-sdk": "0.18.4" for my project.
However, when I try npm ci, it shows this error.
Screenshot (19)

I checked the package.json of avalanche-wallet-sdk and it uses 3.15.2. Since the most recent version of "avalanche" is 3.15.5 I think it should be updated to 3.15.5 . Or, is there anything else I can do to solve this issue?

Bug/Feature: insufficient funds

Current dev version at least.
Wayt to reproduce bug:
`

  1. create singlekeywallet
  2. make exportX( "1000000000", "C",)
    ... you will get "Insufficient Funds error"

How I fixed it

async exportX(amountAvax: string, destination:ExportChainsX): Promise<string> {
    // const fee: BN = xChain.getDefaultTxFee();
    const amount:BN = new BN(amountAvax);
    // FIX make SingleWallet to update it's uxtos
    const uxtos = await this.swallet.updateUtxosX()
    console.log("destination fro X to ", destination2);//, uxtos);
    return this.swallet.exportXChain(amount, destination2);
  }

I think there should be way to refresh Wallet state after constructing it / I understand the need separate routines which makes network calls and which are not

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.