@solana/web3.js 2.0.0-experimental.cc1b7bb → 2.0.0-experimental.cc545f9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Solana Labs, Inc
1
+ Copyright (c) 2023 Solana Labs, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ [![npm][npm-image]][npm-url]
2
+ [![npm-downloads][npm-downloads-image]][npm-url]
3
+ [![semantic-release][semantic-release-image]][semantic-release-url]
4
+ <br />
5
+ [![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
6
+
7
+ [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
+ [code-style-prettier-url]: https://github.com/prettier/prettier
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js/experimental.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/web3.js/experimental.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/web3.js/v/experimental
12
+ [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
+ [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
+
15
+ # Experimental Solana JavaScript SDK
16
+
17
+ Use this to interact with accounts and programs on the Solana network through the Solana [JSON-RPC API](https://docs.solana.com/apps/jsonrpc-api).
18
+
19
+ **This library is experimental**. It is unsuitable for production use, because the API is unstable and may change without warning. If you want to build a production Solana application, use the [1.x branch](https://www.npmjs.com/package/@solana/web3.js).
20
+
21
+ ## Installation
22
+
23
+ ### For use in Node.js, React Native, or a web application
24
+
25
+ ```shell
26
+ npm install --save @solana/web3.js@experimental
27
+ ```
28
+
29
+ ### For use in a browser, without a build system
30
+
31
+ ```html
32
+ <!-- Development (debug mode, unminified) -->
33
+ <script src="https://unpkg.com/@solana/web3.js@experimental/dist/index.development.js"></script>
34
+
35
+ <!-- Production (minified) -->
36
+ <script src="https://unpkg.com/@solana/web3.js@experimental/dist/index.production.min.js"></script>
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ There are 3 main applications of this library.
42
+
43
+ 1. **RPC**. Solana apps interact with the network by calling methods on the Solana JSON-RPC.
44
+ 2. **Transactions**. Solana apps interact with Solana program by building and sending transactions.
45
+ 3. **Keys**. People use cryptographic keys to verify the provenance of messages and to attest to the ownership of their accounts.
46
+
47
+ ### RPC
48
+
49
+ First, configure your connection to an RPC server. This might be a server that you host, one that you lease, or one of the limited-use [public RPC servers](https://docs.solana.com/cluster/rpc-endpoints).
50
+
51
+ ```ts
52
+ import { createDefaultRpcTransport } from '@solana/web3.js';
53
+ const devnetTransport = createDefaultRpcTransport({ url: 'https://api.devnet.solana.com' });
54
+ ```
55
+
56
+ Second, construct an RPC instance that uses that transport.
57
+
58
+ ```ts
59
+ const devnetRpc = createSolanaRpc({ transport: devnetTransport });
60
+ ```
61
+
62
+ Now, you can use it to call methods on your RPC server. For instance, here is how you would fetch an account's balance.
63
+
64
+ ```ts
65
+ const systemProgramAddress = '11111111111111111111111111111111' as Base58EncodedAddress;
66
+ const balanceInLamports = await devnetRpc.getBalance(systemProgramAddress).send();
67
+ console.log('Balance of System Program account in Lamports', balanceInLamports);
68
+ ```
69
+
70
+ ### Transactions
71
+
72
+ Unimplemented.
73
+
74
+ ### Keys
75
+
76
+ #### Addresses and public keys
77
+
78
+ Client applications primarily deal with addresses and public keys in the form of base58-encoded strings. Addresses and public keys returned from the RPC API conform to the type `Base58EncodedAddress`. You can use a value of that type wherever a base58-encoded address or key is expected.
79
+
80
+ From time to time you might acquire a string, that you expect to validate as an address, from an untrusted network API or user input. To assert that such an arbitrary string is a base58-encoded address, use the `assertIsAddress` function.
81
+
82
+ ```ts
83
+ import { assertIsAddress } from '@solana/web3.js';
84
+
85
+ // Imagine a function that fetches an account's balance when a user submits a form.
86
+ async function handleSubmit() {
87
+ // We know only that what the user typed conforms to the `string` type.
88
+ const address: string = accountAddressInput.value;
89
+ try {
90
+ // If this type assertion function doesn't throw, then
91
+ // Typescript will upcast `address` to `Base58EncodedAddress`.
92
+ assertIsAddress(address);
93
+ // At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC.
94
+ const balanceInLamports = await rpc.getBalance(address).send();
95
+ } catch (e) {
96
+ // `address` turned out not to be a base58-encoded address
97
+ }
98
+ }
99
+ ```