-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add readme, fix types + bugs, add example file
- Loading branch information
Showing
6 changed files
with
100 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 🎁 ar-wrapper | ||
A thin wrapper around [`arweave-js`](https://github.com/ArweaveTeam/arweave-js) for versioned permaweb document management. | ||
Helps to abstract away complexity for document storage for servers which front | ||
transaction + gas costs for users. Includes local caching for optimistic transaction executions. | ||
|
||
Usage of this library requires possession of a Arweave keyfile for a wallet which | ||
has funds. | ||
|
||
You can look at `example.js` for annotated usage of this library. | ||
Type definitions can be found in `index.d.ts`. | ||
|
||
### Installation | ||
```bash | ||
npm i ar-wrapper | ||
``` | ||
|
||
```js | ||
const { ArweaveClient } = require('ar-wrapper') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { ArweaveClient } = require('./index') | ||
|
||
// Address of your admin wallet with funds | ||
const address = "..." | ||
// Contents of your wallet JSON keyfile. Ideally do NOT hardcode this! Use environment variables or DI. | ||
const keyfile = `{...}` | ||
|
||
// Main driver logic (using a main function to allow use of async-await features) | ||
async function main() { | ||
// Instantiate client | ||
const client = new ArweaveClient(address, keyfile) | ||
|
||
// create a new document | ||
const doc = await client.addDocument("Test Document", "Lorem Ipsum", { | ||
"hasTag": true | ||
}) | ||
|
||
// update document content (note the version bump!) | ||
await doc.update("Woah, new content!") | ||
|
||
// see if content is cached locally | ||
// version 0 is no longer cached! | ||
console.log(`Is 'Test Document'@0 cached? ${client.isCached("Test Document", 0)}`) | ||
// but version 1 is | ||
console.log(`Is 'Test Document'@1 cached? ${client.isCached("Test Document", 1)}`) | ||
|
||
// fetch latest document content (if version is omitted, latest is fetched) | ||
console.log(await client.getDocumentByName("Test Document")) | ||
|
||
// fetch specific version | ||
// this is no longer in cache so will try to fetch from network | ||
// this might take a long while (>2min) because of block confirmation times | ||
// so will most likely timeout!! | ||
console.log(await client.getDocumentByName("Test Document", 0)) | ||
|
||
// get specific document by transaction (that you know exists) | ||
console.log(await client.getDocumentByTxId("v-KCk3wHsrJdCShnXigOZaJzMpddqKvdHVgdYoxB_8w")) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters