@withautonomi/autonomi 0.2.2-rc.2 → 0.2.2-rc.3

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.
Files changed (2) hide show
  1. package/README.md +18 -147
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,159 +1,30 @@
1
- # `autonomi` - Autonomi client API
1
+ # JavaScript Autonomi API Documentation
2
2
 
3
- [![Crates.io](https://img.shields.io/crates/v/autonomi.svg)](https://crates.io/crates/autonomi)
4
- [![docs.rs](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/autonomi)
3
+ Note that this is a first version and will be subject to change.
5
4
 
6
- Connect to and build on the Autonomi network.
5
+ The entry point for connecting to the network is {@link Client.connect}.
7
6
 
8
- ## Usage
7
+ This API is a wrapper around the Rust API, found here: https://docs.rs/autonomi/latest/autonomi. The Rust API contains more detailed documentation on concepts and some types.
9
8
 
10
- Add the autonomi crate to your `Cargo.toml`:
9
+ ## Addresses
11
10
 
12
- ```toml
13
- [dependencies]
14
- autonomi = { path = "../autonomi", version = "0.1.0" }
15
- ```
16
-
17
- ## Running tests
18
-
19
- ### Using a local EVM testnet
20
-
21
- 1. If you haven't, install Foundry, to be able to run Anvil
22
- nodes: https://book.getfoundry.sh/getting-started/installation
23
- 2. Run a local EVM node:
24
-
25
- ```sh
26
- cargo run --bin evm_testnet
27
- ```
28
-
29
- 3. Run a local network with the `local` feature and use the local evm node.
30
-
31
- ```sh
32
- cargo run --bin=safenode-manager --features=local -- local run --build --clean --rewards-address <ETHEREUM_ADDRESS> evm-local
33
- ```
34
-
35
- 4. Then run the tests with the `local` feature and pass the EVM params again:
36
-
37
- ```sh
38
- EVM_NETWORK=local cargo test --package=autonomi --features=local
39
- # Or with logs
40
- RUST_LOG=autonomi EVM_NETWORK=local cargo test --package=autonomi --features=local -- --nocapture
41
- ```
42
-
43
- ### Using a live testnet or mainnet
44
-
45
- Using the hardcoded `Arbitrum One` option as an example, but you can also use the command flags of the steps above and
46
- point it to a live network.
47
-
48
- 1. Run a local network with the `local` feature:
49
-
50
- ```sh
51
- cargo run --bin=safenode-manager --features=local -- local run --build --clean --rewards-address <ETHEREUM_ADDRESS> evm-arbitrum-one
52
- ```
53
-
54
- 2. Then run the tests with the `local` feature. Make sure that the wallet of the private key you pass has enough gas and
55
- payment tokens on the network (in this case Arbitrum One):
56
-
57
- ```sh
58
- EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local
59
- # Or with logs
60
- RUST_LOG=autonomi EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local -- --nocapture
61
- ```
62
-
63
- ### WebAssembly
64
-
65
- To run a WASM test
66
-
67
- - Install `wasm-pack`
68
- - Make sure your Rust supports the `wasm32-unknown-unknown` target. (If you
69
- have `rustup`: `rustup target add wasm32-unknown-unknown`.)
70
- - Pass a bootstrap peer via `SAFE_PEERS`. This *has* to be the websocket address,
71
- e.g. `/ip4/<ip>/tcp/<port>/ws/p2p/<peer ID>`.
72
- - As well as the other environment variables needed for EVM payments (e.g. `RPC_URL`).
73
- - Optionally specify the specific test, e.g. `-- put` to run `put()` in `wasm.rs` only.
11
+ For addresses (chunk, data, archives, etc) we're using hex-encoded strings containing a 256-bit XOR addresse. For example: `abcdefg012345678900000000000000000000000000000000000000000000000`.
74
12
 
75
- Example:
13
+ ## Example
76
14
 
77
- ```sh
78
- SAFE_PEERS=/ip4/<ip>/tcp/<port>/ws/p2p/<peer ID> wasm-pack test --release --firefox autonomi --features=data,files --test wasm -- put
79
- ```
80
-
81
- #### Test from JS in the browser
82
-
83
- `wasm-pack test` does not execute JavaScript, but runs mostly WebAssembly. Again make sure the environment variables are
84
- set and build the JS package:
85
-
86
- ```sh
87
- wasm-pack build --dev --target=web autonomi --features=vault
88
- ```
89
-
90
- Then cd into `autonomi/tests-js`, and use `npm` to install and serve the test html file.
15
+ ```javascript
16
+ import init, { Client, Wallet, getEvmNetwork } from 'autonomi';
91
17
 
92
- ```
93
- cd autonomi/tests-js
94
- npm install
95
- npm run serve
96
- ```
97
-
98
- Then go to `http://127.0.0.1:8080/tests-js` in the browser. Here, enter a `ws` multiaddr of a local node and press '
99
- run'.
18
+ let client = await new Client(["/ip4/127.0.0.1/tcp/36075/ws/p2p/12D3KooWALb...BhDAfJY"]);
19
+ console.log("connected");
100
20
 
101
- #### MetaMask example
21
+ let wallet = Wallet.new_from_private_key(getEvmNetwork, "your_private_key_here");
22
+ console.log("wallet retrieved");
102
23
 
103
- There is a MetaMask example for doing a simple put operation.
24
+ let data = new Uint8Array([1, 2, 3]);
25
+ let result = await client.put(data, wallet);
26
+ console.log("Data stored at:", result);
104
27
 
105
- Build the package with the `external-signer` feature (and again with the env variables) and run a webserver, e.g. with
106
- Python:
107
-
108
- ```sh
109
- wasm-pack build --dev --target=web autonomi --features=external-signer
110
- python -m http.server --directory=autonomi 8000
28
+ let fetchedData = await client.get(result);
29
+ console.log("Data retrieved:", fetchedData);
111
30
  ```
112
-
113
- Then visit `http://127.0.0.1:8000/examples/metamask` in your (modern) browser.
114
-
115
- Here, enter a `ws` multiaddr of a local node and press 'run'.
116
-
117
- ## Faucet (local)
118
-
119
- There is no faucet server, but instead you can use the `Deployer wallet private key` printed in the EVM node output to
120
- initialise a wallet from with almost infinite gas and payment tokens. Example:
121
-
122
- ```rust
123
- let rpc_url = "http://localhost:54370/";
124
- let payment_token_address = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
125
- let data_payments_address = "0x8464135c8F25Da09e49BC8782676a84730C318bC";
126
- let private_key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
127
-
128
- let network = Network::Custom(CustomNetwork::new(
129
- rpc_url,
130
- payment_token_address,
131
- data_payments_address,
132
- ));
133
-
134
- let deployer_wallet = Wallet::new_from_private_key(network, private_key).unwrap();
135
- let receiving_wallet = Wallet::new_with_random_wallet(network);
136
-
137
- // Send 10 payment tokens (atto)
138
- let _ = deployer_wallet
139
- .transfer_tokens(receiving_wallet.address(), Amount::from(10))
140
- .await;
141
- ```
142
-
143
- Alternatively, you can provide the wallet address that should own all the gas and payment tokens to the EVM testnet
144
- startup command using the `--genesis-wallet` flag:
145
-
146
- ```sh
147
- cargo run --bin evm_testnet -- --genesis-wallet <ETHEREUM_ADDRESS>
148
- ```
149
-
150
- ```shell
151
- *************************
152
- * Ethereum node started *
153
- *************************
154
- RPC URL: http://localhost:60093/
155
- Payment token address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
156
- Chunk payments address: 0x8464135c8F25Da09e49BC8782676a84730C318bC
157
- Deployer wallet private key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
158
- Genesis wallet balance: (tokens: 20000000000000000000000000, gas: 9998998011366954730202)
159
- ```
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "MaidSafe Developers <dev@maidsafe.net>"
6
6
  ],
7
7
  "description": "Autonomi client API",
8
- "version": "0.2.2-rc.2",
8
+ "version": "0.2.2-rc.3",
9
9
  "license": "GPL-3.0",
10
10
  "repository": {
11
11
  "type": "git",
@@ -22,4 +22,4 @@
22
22
  "sideEffects": [
23
23
  "./snippets/*"
24
24
  ]
25
- }
25
+ }