0.3.63 • Published 8 months ago

@thencc/algonautjs v0.3.63

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Algonaut.js

Examples | API Docs

Algonaut.js is designed to be a front end developer friendly and browser friendly library to facilitate intuitive transactions on the Algorand network. Algorand is incredibly fast, powerful and secure, but it's early days and the tooling is still a little intense.

After working with the existing frameworks for a couple months, we decided to just create what we felt was missing! Get in here and help!

THE GOAL OF THIS LIBRARY IS SIMPLICITY AND EASE OF USE for the front end crew. This library aims to bring you closer to key concepts behind the mature transactional fiesta that is Algorand though ease of use. If you need a robust contract creation and debugging environment, please take the wonderful Algo Builder for a spin!

API Approach

We package, expose and depend on the JavaScript Algosdk. It's there if you need it, but that API is pretty intense for day-to-day use. With Algonaut.js, you can run one-off transactions with a vastly simplified API as compared to transacting with the Algosdk directly. We're trying to solve for the 90% cases and ask you to dive into the hard stuff only if you actually need to use it.

To create an instance with a node and get ready to transact:

import AlgonautJS from '@thencc/algonautjs';

const algonaut = new AlgonautJS({
  BASE_SERVER: 'https://testnet-algorand.api.purestake.io/ps2',
  LEDGER: 'TestNet',
  PORT: '',
  API_TOKEN: { 'X-API-Key': 'MY_KEY_HERE' },
  SIGNING_MODE: 'wallet-connect' // this is mandatory if you are using WalletConnect!
});

algonaut.recoverAccount(a_mnemonic_phrase);

Atomic Transactions

One of the most powerful aspects of the Algorand chain is the ability to group transactions together and run them as one. The API for this is, again, pretty hard to folow for your average FED. With Algonaut.js, the aim is to make using this incredibly powerful API simple and intuitive:

// this transaction must pay and and then make a request to an Algorand Smart Contract
// in one transaction. It must also include the asset index in the "assets" arg and an
// app index in the applications arg
const status = await algonaut.sendAtomicTransaction([
  await algonaut.atomicPayment({ to: appAddress, amount: 250000 }),
  await algonaut.atomicCallApp({
    appIndex: appIndex,
    appArgs: ['get_bananas'],
    optionalFields: { applications: [ bananaPriceTicker ] , assets: [ bananaAsaIndex ]
  })
])

Interacting with Smart Contracts

Algorand smart contracts are fast, light, and super clean. Trying to communicate their APIs across our team has been really hard. For that reason, Algonaut.js supports a simple TypeScript descriptor for both Stateful and Stateless Smart contracts. The goal is to be able to load this TypeScript descriptor into your dev envirnment and get a sense of what you can and can't do with a contract's API.

Even the concept of Stateless contracts will be a curve climb for a lot of front end people. Our goal with this descriptor approach is to communicate a baseline of information about what transactions are permitted, expected, etc, without the front-end developer needing to go into the TEAL or PyTeal directly to figure this stuff out.

Here again we are trying to account for the 90% use case, not every possible case. The goal is simplicity and ease of use, understanding that there will always be those complex cases where you have to go down to the metal.

const response = await algonaut.callApp(
  {
    appIndex: 123456789,
    appArgs: ['set_name', 'New Name']
  }
);

Usage

Install from NPM:

npm install @thencc/algonautjs --save

Usage:

import Algonaut from '@thencc/algonautjs';
const algonaut = new Algonaut({
  BASE_SERVER: 'https://testnet-algorand.api.purestake.io/ps2',
  LEDGER: 'TestNet',
  PORT: '',
  API_TOKEN: { 'X-API-Key': 'YOUR_API_TOKEN' }
});

const account = algonaut.recoverAccount("a mnemonic phrase");
algonaut.setAccount(account);

const txnStatus = await algonaut.sendAlgo({
  to: "toAddress",
  amount: 1000,
  optionalFields: { note: "a note for the transaction" }
});
console.log(txnStatus);

Testing

Rudimentary tests done in test/ dir.

  1. Create an .env file with PURESTAKE_API_TOKEN and ALGONAUT_TEST_MNEMONIC set.
  2. Run npm run test
  3. If you make changes to algonaut while testing, run npm run build before running tests.

Contributing

To generate docs:

npm run docs

Typedoc options are set in typedoc.json.


Publishing to NPM:

latest/release stable releases have the default npm tag of latest (installable via npm i @thencc/algonautjs or npm i @thencc/algonautjs@latest) and are automatically published from the repo's release branch via a Github Action. so simply pull request the main branch (or feature specific branch) into release to publish to npm.

beta/main similarly, pushing commits or merging pull requests to the repo's main branch will automatically publish to the npm beta release installable via npm i @thencc/algonautjs@beta.

note:

  • to update either the latest or beta releases, the version in package.json must be higher than the previous release.

TBD:

  • setting up a dev env
  • ESLint and code style
  • building and testing with Vite and Node
0.3.70

8 months ago

0.3.64

9 months ago

0.3.63

9 months ago

0.3.62

10 months ago

0.3.61

10 months ago

0.3.69

8 months ago

0.3.68

8 months ago

0.3.67

8 months ago

0.3.66

8 months ago

0.3.65

9 months ago

0.3.60

10 months ago

0.3.59

11 months ago

0.3.58

11 months ago

0.3.57

11 months ago

0.3.56

11 months ago

0.3.55

11 months ago

0.3.54

11 months ago

0.3.53

11 months ago

0.3.52

11 months ago

0.3.51

11 months ago

0.3.50

11 months ago

0.3.42

11 months ago

0.3.41

11 months ago

0.3.40

11 months ago

0.3.49

11 months ago

0.3.48

11 months ago

0.3.47

11 months ago

0.3.46

11 months ago

0.3.45

11 months ago

0.3.44

11 months ago

0.3.43

11 months ago

0.3.31

11 months ago

0.3.30

12 months ago

0.3.39

11 months ago

0.3.38

11 months ago

0.3.37

11 months ago

0.3.36

11 months ago

0.3.35

11 months ago

0.3.34

11 months ago

0.3.33

11 months ago

0.3.32

11 months ago

0.3.29

12 months ago

0.3.20

12 months ago

0.3.28

12 months ago

0.3.27

12 months ago

0.3.26

12 months ago

0.3.25

12 months ago

0.3.24

12 months ago

0.3.23

12 months ago

0.3.22

12 months ago

0.3.21

12 months ago

0.3.19

12 months ago

0.3.18

12 months ago

0.3.17

12 months ago

0.3.16

12 months ago

0.3.15

12 months ago

0.3.14

12 months ago

0.3.13

12 months ago

0.3.12

12 months ago

0.3.0

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.2.115

1 year ago

0.2.114

1 year ago

0.2.113

1 year ago

0.2.112

1 year ago

0.2.111

1 year ago

0.2.110

1 year ago

0.2.109

1 year ago

0.2.108

1 year ago

0.2.107

1 year ago

0.2.106

1 year ago

0.3.9

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.2.96

1 year ago

0.2.94

1 year ago

0.2.93

1 year ago

0.2.92

1 year ago

0.2.91

1 year ago

0.2.90

1 year ago

0.2.99

1 year ago

0.2.98

1 year ago

0.2.97

1 year ago

0.2.85

1 year ago

0.2.84

1 year ago

0.2.82

1 year ago

0.2.81

1 year ago

0.2.80

1 year ago

0.2.89

1 year ago

0.2.88

1 year ago

0.2.87

1 year ago

0.2.86

1 year ago

0.2.74

1 year ago

0.2.73

1 year ago

0.2.72

1 year ago

0.2.71

1 year ago

0.2.70

1 year ago

0.2.79

1 year ago

0.2.78

1 year ago

0.2.77

1 year ago

0.2.76

1 year ago

0.2.75

1 year ago

0.2.63

1 year ago

0.2.62

1 year ago

0.2.61

1 year ago

0.2.105

1 year ago

0.2.60

1 year ago

0.2.104

1 year ago

0.2.102

1 year ago

0.2.101

1 year ago

0.2.69

1 year ago

0.2.68

1 year ago

0.2.67

1 year ago

0.2.65

1 year ago

0.2.64

1 year ago

0.2.59

1 year ago

0.2.58

1 year ago

0.2.57

1 year ago

0.2.27

1 year ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.22

1 year ago

0.2.21

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.52

1 year ago

0.2.51

1 year ago

0.2.56

1 year ago

0.2.55

1 year ago

0.2.54

1 year ago

0.2.53

1 year ago

0.2.40

1 year ago

0.2.49

1 year ago

0.2.48

1 year ago

0.2.47

1 year ago

0.2.46

1 year ago

0.2.45

1 year ago

0.2.44

1 year ago

0.2.43

1 year ago

0.2.42

1 year ago

0.2.39

1 year ago

0.2.30

1 year ago

0.2.38

1 year ago

0.2.37

1 year ago

0.2.36

1 year ago

0.2.35

1 year ago

0.2.33

1 year ago

0.2.32

1 year ago

0.2.31

1 year ago

0.2.29

1 year ago

0.2.28

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.3

1 year ago

0.2.5

1 year ago

0.1.74

2 years ago

0.1.75

2 years ago

0.1.76

2 years ago

0.1.77

2 years ago

0.1.78

2 years ago

0.1.70

2 years ago

0.1.71

2 years ago

0.1.72

2 years ago

0.1.73

2 years ago

0.1.69

2 years ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.1.63

2 years ago

0.1.64

2 years ago

0.1.65

2 years ago

0.1.66

2 years ago

0.1.67

2 years ago

0.1.68

2 years ago

0.1.61

2 years ago

0.1.62

2 years ago

0.1.59

2 years ago

0.1.60

2 years ago

0.1.58

2 years ago

0.1.57

2 years ago