2020-09-09 16:57:30 -07:00
|
|
|
# Token JavaScript API
|
2020-06-05 11:34:17 -07:00
|
|
|
|
|
|
|
The Token JavaScript library comprises:
|
|
|
|
|
|
|
|
* A library to interact with the on-chain program
|
|
|
|
* A test client that exercises the program
|
|
|
|
* Scripts to facilitate building the program
|
|
|
|
|
|
|
|
## Getting Started
|
|
|
|
|
|
|
|
First fetch the npm dependencies, including `@solana/web3.js`, by running:
|
2020-07-28 11:00:37 -07:00
|
|
|
```bash
|
2020-06-05 11:34:17 -07:00
|
|
|
$ npm install
|
|
|
|
```
|
|
|
|
|
|
|
|
### Select a Network
|
|
|
|
|
|
|
|
The client connects to a local Solana cluster by default.
|
|
|
|
|
|
|
|
To enable on-chain program logs, set the `RUST_LOG` environment variable:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ export RUST_LOG=solana_runtime::native_loader=trace,solana_runtime::system_instruction_processor=trace,solana_runtime::bank=debug,solana_bpf_loader=debug,solana_rbpf=debug
|
|
|
|
```
|
|
|
|
|
|
|
|
To start a local Solana cluster run:
|
|
|
|
```bash
|
2020-12-17 16:11:10 -08:00
|
|
|
$ solana-test-validator
|
2020-06-05 11:34:17 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Solana cluster logs are available with:
|
|
|
|
```bash
|
2020-12-17 16:11:10 -08:00
|
|
|
$ solana --url http://127.0.0.1:8899/ logs
|
2020-06-05 11:34:17 -07:00
|
|
|
```
|
|
|
|
|
2020-07-28 11:00:37 -07:00
|
|
|
### Build the on-chain program
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ npm run build:program
|
|
|
|
```
|
2020-06-05 11:34:17 -07:00
|
|
|
|
|
|
|
### Run the test client
|
|
|
|
|
2020-07-28 11:00:37 -07:00
|
|
|
```bash
|
2020-06-05 11:34:17 -07:00
|
|
|
$ npm run start
|
|
|
|
```
|
|
|
|
|
|
|
|
## Pointing to a public Solana cluster
|
|
|
|
|
|
|
|
Solana maintains three public clusters:
|
|
|
|
- `devnet` - Development cluster with airdrops enabled
|
|
|
|
- `testnet` - Tour De Sol test cluster without airdrops enabled
|
|
|
|
- `mainnet-beta` - Main cluster
|
|
|
|
|
|
|
|
Use npm scripts to configure which cluster.
|
|
|
|
|
|
|
|
To point to `devnet`:
|
|
|
|
```bash
|
|
|
|
$ npm run cluster:devnet
|
|
|
|
```
|
|
|
|
|
|
|
|
To point back to the local cluster:
|
|
|
|
```bash
|
|
|
|
$ npm run cluster:localnet
|
|
|
|
```
|