2018-09-21 08:57:19 -07:00
|
|
|
[![Build status][travis-image]][travis-url]
|
|
|
|
[![codecov][codecov-image]][codecov-url]
|
|
|
|
[![esdoc][esdoc-image]][esdoc-url]
|
2018-09-22 10:32:48 -07:00
|
|
|
<br>
|
2018-09-21 08:57:19 -07:00
|
|
|
[![npm][npm-image]][npm-url]
|
2018-09-22 10:32:48 -07:00
|
|
|
[![npm-downloads][npm-downloads-image]][npm-url]
|
2018-09-21 09:01:26 -07:00
|
|
|
[![david][david-deps-image]][david-deps-url]
|
|
|
|
[![david][david-dev-deps-image]][david-dev-deps-url]
|
2018-11-07 10:50:21 -08:00
|
|
|
<br>
|
2018-10-01 08:12:14 -07:00
|
|
|
[![semantic-release][semantic-release-image]][semantic-release-url]
|
2018-11-07 10:50:21 -08:00
|
|
|
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
2018-09-21 08:57:19 -07:00
|
|
|
|
|
|
|
[travis-image]: https://api.travis-ci.org/solana-labs/solana-web3.js.svg?branch=master
|
|
|
|
[travis-url]: https://travis-ci.org/solana-labs/solana-web3.js
|
|
|
|
[codecov-image]: https://codecov.io/gh/solana-labs/solana-web3.js/branch/master/graph/badge.svg
|
|
|
|
[codecov-url]: https://codecov.io/gh/solana-labs/solana-web3.js
|
|
|
|
[esdoc-image]: https://solana-labs.github.io/solana-web3.js/badge.svg
|
|
|
|
[npm-image]: https://img.shields.io/npm/v/@solana/web3.js.svg?style=flat
|
2018-09-22 10:32:48 -07:00
|
|
|
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js.svg?style=flat
|
2018-09-21 08:57:19 -07:00
|
|
|
[esdoc-url]: https://solana-labs.github.io/solana-web3.js/
|
|
|
|
[npm-url]: https://www.npmjs.com/package/@solana/web3.js
|
2018-09-21 09:01:26 -07:00
|
|
|
[david-deps-image]: https://david-dm.org/solana-labs/solana-web3.js.svg
|
|
|
|
[david-deps-url]: https://david-dm.org/solana-labs/solana-web3.js
|
|
|
|
[david-dev-deps-image]: https://david-dm.org/solana-labs/solana-web3.js/dev-status.svg
|
|
|
|
[david-dev-deps-url]: https://david-dm.org/solana-labs/solana-web3.js?type=dev
|
2018-10-01 08:12:14 -07:00
|
|
|
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
|
|
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
2018-11-07 10:50:21 -08:00
|
|
|
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
|
|
[code-style-prettier-url]: https://github.com/prettier/prettier
|
2018-08-22 13:30:04 -07:00
|
|
|
|
|
|
|
# Solana JavaScript API
|
|
|
|
|
2018-12-07 07:44:18 -08:00
|
|
|
This is the Solana Javascript API built on the Solana [JSON RPC API](https://solana-labs.github.io/solana/jsonrpc-api.html)
|
2018-08-22 13:30:04 -07:00
|
|
|
|
2018-08-22 13:53:13 -07:00
|
|
|
[Latest API Documentation](https://solana-labs.github.io/solana-web3.js/)
|
2018-08-22 13:30:04 -07:00
|
|
|
|
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
## Installation
|
2018-08-22 20:06:29 -07:00
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
### Yarn
|
|
|
|
```
|
|
|
|
$ yarn add @solana/web3.js
|
|
|
|
```
|
|
|
|
|
|
|
|
### npm
|
2018-08-22 20:06:29 -07:00
|
|
|
```
|
|
|
|
$ npm install --save @solana/web3.js
|
|
|
|
```
|
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
### Browser bundle
|
|
|
|
```html
|
2018-09-13 19:55:56 -07:00
|
|
|
<script src="https://github.com/solana-labs/solana-web3.js/releases/download/v0.0.6/solanaWeb3.min.js"></script>
|
2018-08-23 08:12:51 -07:00
|
|
|
```
|
2018-08-22 20:06:29 -07:00
|
|
|
|
2018-11-01 10:06:06 -07:00
|
|
|
### BPF program development
|
|
|
|
clang-7.0 must be installed to build BPF programs, such as
|
|
|
|
`examples/bpf-c-noop/`. See `bpf-sdk/README.md` for installation details
|
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
## Usage
|
2018-08-22 20:06:29 -07:00
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
### Javascript
|
|
|
|
```js
|
|
|
|
const solanaWeb3 = require('@solana/web3.js');
|
|
|
|
console.log(solanaWeb3);
|
|
|
|
```
|
2018-08-22 20:06:29 -07:00
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
### ES6
|
|
|
|
```js
|
|
|
|
import solanaWeb3 from '@solana/web3.js';
|
|
|
|
console.log(solanaWeb3);
|
|
|
|
```
|
|
|
|
|
|
|
|
### Browser bundle
|
|
|
|
```js
|
|
|
|
// `solanaWeb3` is provided in the global namespace by the `solanaWeb3.min.js` script bundle.
|
|
|
|
console.log(solanaWeb3);
|
|
|
|
```
|
2018-08-22 13:30:04 -07:00
|
|
|
|
2018-10-02 20:51:19 -07:00
|
|
|
## Local Network
|
2018-10-02 21:55:39 -07:00
|
|
|
The `solana-localnet` program is provided to easily start a test Solana network
|
2018-10-02 20:51:19 -07:00
|
|
|
locally on your machine. Docker must be installed. The JSON RPC endpoint of
|
|
|
|
the local network is `http://localhost:8899`.
|
|
|
|
|
|
|
|
To start, first fetch the latest Docker image by running:
|
|
|
|
```bash
|
|
|
|
$ npx solana-localnet update
|
|
|
|
```
|
|
|
|
|
|
|
|
Then run the following command to start the network
|
|
|
|
```bash
|
|
|
|
$ npx solana-localnet up
|
|
|
|
```
|
|
|
|
|
|
|
|
While the network is running logs are available with:
|
|
|
|
```bash
|
|
|
|
$ npx solana-localnet logs -f
|
|
|
|
```
|
|
|
|
|
|
|
|
Stop the network with:
|
|
|
|
```bash
|
2018-10-14 19:52:52 -07:00
|
|
|
$ npx solana-localnet down
|
2018-10-02 20:51:19 -07:00
|
|
|
```
|
|
|
|
|
2018-09-28 20:18:57 -07:00
|
|
|
## Flow
|
|
|
|
|
2018-09-28 21:25:10 -07:00
|
|
|
A [Flow library definition](https://flow.org/en/docs/libdefs/) is provided at
|
2018-09-28 20:18:57 -07:00
|
|
|
[module.flow.js](https://github.com/solana-labs/solana-web3.js/tree/master/module.flow.js).
|
|
|
|
Add the following line under the [libs] section of your project's .flowconfig to
|
|
|
|
activate it:
|
|
|
|
```ini
|
|
|
|
[libs]
|
|
|
|
node_modules/@solana/web3.js/module.flow.js
|
|
|
|
```
|
|
|
|
|
2018-08-23 08:12:51 -07:00
|
|
|
## Examples
|
2018-09-25 19:18:24 -07:00
|
|
|
See the [examples/](https://github.com/solana-labs/solana-web3.js/tree/master/examples) directory for small snippets.
|
2018-08-23 20:29:27 -07:00
|
|
|
|
2018-09-25 19:18:24 -07:00
|
|
|
Standalone examples:
|
|
|
|
* Web wallet: https://github.com/solana-labs/example-webwallet
|
|
|
|
* Tic-tac-toe: https://github.com/solana-labs/example-tictactoe
|
2018-08-23 08:12:51 -07:00
|
|
|
|
|
|
|
## Releases
|
2018-08-22 20:06:29 -07:00
|
|
|
Releases are available on [Github](https://github.com/solana-labs/solana-web3.js/releases)
|
2018-08-24 09:07:15 -07:00
|
|
|
and [npmjs.com](https://www.npmjs.com/package/@solana/web3.js)
|
2018-08-22 13:30:04 -07:00
|
|
|
|
2018-08-23 16:39:43 -07:00
|
|
|
Each Github release features a tarball containing API documentation and a
|
|
|
|
minified version of the module suitable for direct use in a browser environment
|
|
|
|
(<script> tag)
|