solana/web3.js
Trent Nelson 24d18b3cf2 docs: add docs links for crates published to crates.io 2021-03-11 08:38:18 +00:00
..
.github
.travis
bin
css
examples docs: add docs links for crates published to crates.io 2021-03-11 08:38:18 +00:00
flow-typed/npm
src
test
.esdoc.json
.eslintignore
.eslintrc.js
.flowconfig
.gitignore
.mergify.yml
.mocharc.js
.prettierignore
.prettierrc.yaml
.sgcrc
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
babel.config.json
commitlint.config.js
mocha.html
module.d.ts
module.flow.js
package-lock.json
package.json
rollup.config.js

README.md

Build status codecov esdoc
npm npm-downloads
semantic-release code-style-prettier

Solana JavaScript API

This is the Solana Javascript API built on the Solana JSON RPC API

Latest API Documentation

Installation

Yarn

$ yarn add @solana/web3.js

npm

$ npm install --save @solana/web3.js

Browser bundle

<!-- Development (un-minified) -->
<script src="https://unpkg.com/@solana/[email protected]/lib/index.iife.js"></script>

<!-- Production (un-minified) -->
<script src="https://unpkg.com/@solana/[email protected]/lib/index.iife.min.js"></script>

Development Environment Setup

To build and run tests:

  1. Install Rust from https://rustup.rs/
  2. Install the latest Solana release from https://docs.solana.com/cli/install-solana-cli-tools

Usage

Javascript

const solanaWeb3 = require('@solana/web3.js');
console.log(solanaWeb3);

ES6

import solanaWeb3 from '@solana/web3.js';
console.log(solanaWeb3);

Browser bundle

// `solanaWeb3` is provided in the global namespace by the `solanaWeb3.min.js` script bundle.
console.log(solanaWeb3);

Flow

A Flow library definition is provided at module.flow.js. Add the following line under the [libs] section of your project's .flowconfig to activate it:

[libs]
node_modules/@solana/web3.js/module.flow.js

Examples

See the examples/ directory for small snippets.

Standalone examples:

Releases

Releases are available on Github and npmjs.com

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)

Deprecated

Local Network

Please use solana-test-validator from the latest Solana release instead of the information in this section

The solana-localnet program is provided to easily start a test Solana cluster locally on your machine. Docker must be installed. The JSON RPC endpoint of the local cluster is http://localhost:8899.

To start, first fetch the latest Docker image by running:

$ npx solana-localnet update

Then run the following command to start the cluster

$ npx solana-localnet up

While the cluster is running logs are available with:

$ npx solana-localnet logs -f

Stop the cluster with:

$ npx solana-localnet down

BPF program development

Please use cargo build-bpf from the latest Solana release instead of the information in this section

The Solana BPF SDK is located in the bpf-sdk/ subdirectory if you installed solana-web3.js from npmjs.com.

From a git clone, run npm run bpf-sdk:install to fetch the latest BPF SDK.

Additionally Rust must be installed to build Rust BPF programs such as examples/bpf-rust-noop/. See https://www.rust-lang.org/install.html for installation details.