Skip to content

Commit

Permalink
docs: simplify the readme js code example (#1174)
Browse files Browse the repository at this point in the history
its better if we direct folks to the docs or the workshopper rather than
try and explain it all here.

License: MIT

Signed-off-by: Oli Evans <oli@protocol.ai>
  • Loading branch information
olizilla authored Nov 21, 2023
1 parent d6217c8 commit 418c0a4
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,31 @@ Run `w3 --help` or have a look at https://github.com/web3-storage/w3cli to find

Add the [`@web3-storage/w3up-client`](https://www.npmjs.com/package/@web3-storage/w3up-client) module into your project with `npm i @web3-storage/w3up-client` and upload a single file with [`client.uploadFile`](https://github.com/web3-storage/w3up/blob/main/packages/w3up-client/README.md#uploadfile) or many with [`client.uploadDirectory`](https://github.com/web3-storage/w3up/blob/main/packages/w3up-client/README.md#uploaddirectory).

If you've already got a space you can authorize your client and upload like this:
If you've already got a space you can upload like this:

**node.js**
```js
import { getFilesFromPaths } from 'files-from-path'
import { filesFromPaths } from 'files-from-path'
import * as Client from '@web3-storage/w3up-client'

const [,,yourEmail, pathToAdd] = process.argv

// authorize your local agent to act on your behalf
const client = await Client.create()
await client.login('you@example.org')
await client.login(yourEmail)

// lets go!
const files = await getFilesFromPaths(process.env.PATH_TO_ADD)
const files = await filesFromPaths(pathToAdd)
const cid = await client.uploadDirectory(files)

console.log(`IPFS CID: ${cid}`)
console.log(`Gateway URL: https://w3s.link/ipfs/${cid}`)
```

To make a new space programmatically use [`client.createSpace`](https://github.com/web3-storage/w3up/blob/main/packages/w3up-client/README.md#createspace)

**node.js**
```js
import * as Client from '@web3-storage/w3up-client'

// authorize your local agent to act on your behalf
const client = await Client.create()
await client.login('you@example.org')

// give you space a nickname to remember it by
const space = await client.createSpace('my space')

console.log(space.name()) // 'my space'
console.log(space.did()) // 'did:key:xyz...'
```

See https://web3.storage/docs/w3up-client for a guide to using the js client for the first time.

For an interactive command line adventure into the using w3up check out `learnyouw3up` here https://github.com/web3-storage/learnyouw3up


## Contributing

Expand Down

0 comments on commit 418c0a4

Please sign in to comment.