Browse Source

improve readme

master
nitowa 2 years ago
parent
commit
4a73cda7aa
2 changed files with 30 additions and 1 deletions
  1. 29
    0
      README.md
  2. 1
    1
      package.json

+ 29
- 0
README.md View File

14
 
14
 
15
 # Quickstart
15
 # Quickstart
16
 ```typescript
16
 ```typescript
17
+import {RippleAPI} from 'ripple-lib'
17
 import {treeRead, treeWrite} from 'xrpio'
18
 import {treeRead, treeWrite} from 'xrpio'
18
 
19
 
19
 const api = new RippleAPI({ server: "..." }) 
20
 const api = new RippleAPI({ server: "..." }) 
31
 
32
 
32
 const data = await treeRead(api, [dataRootHash])
33
 const data = await treeRead(api, [dataRootHash])
33
 console.log(data) //"Arbitrary string data 123"
34
 console.log(data) //"Arbitrary string data 123"
35
+```
36
+
37
+# A simple run-ready example for the testnet
38
+```typescript
39
+import { treeRead, treeWrite, Wallet } from 'xrpio'
40
+import { RippleAPI } from 'ripple-lib'
41
+import fetch from 'node-fetch'
42
+
43
+export const makeTestnetWallet = () : Promise<Wallet> => fetch('https://faucet.altnet.rippletest.net/accounts', {
44
+    method: 'POST',
45
+    headers: {
46
+        'Accept': 'application/json',
47
+        'Content-Type': 'application/json'
48
+    },
49
+}).then((raw:any) => {
50
+    return raw.json().then(content => content.account)
51
+});
52
+
53
+(async()=>{
54
+    const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
55
+    await api.connect()
56
+    const fromWallet = await makeTestnetWallet()
57
+    const toWallet = await makeTestnetWallet()
58
+    await new Promise((res, rej) => setTimeout(res, 10000)) //it takes a moment for the wallets to become active
34
 
59
 
60
+    const rootHash = await treeWrite(api, "test123", fromWallet, toWallet.address)
61
+    const data = await treeRead(api, [rootHash])
62
+    console.log(data)    
63
+})()
35
 ```
64
 ```
36
 
65
 
37
 # [Full documentation](https://gitea.nitowa.xyz/docs/xrpio)
66
 # [Full documentation](https://gitea.nitowa.xyz/docs/xrpio)

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "xrpio",
2
   "name": "xrpio",
3
-  "version": "0.0.2",
3
+  "version": "0.0.3",
4
   "repository": {
4
   "repository": {
5
     "type": "git",
5
     "type": "git",
6
     "url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
6
     "url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"

Loading…
Cancel
Save