Skip to content

Commit 80baa76

Browse files
clean up documentation
1 parent dc3904d commit 80baa76

File tree

9 files changed

+172
-149
lines changed

9 files changed

+172
-149
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
We're really glad you're reading this, because we need volunteer developers to help this project come to fruition. 👏
1+
If you want to contribute, you are very welcome to do so.
22

3-
## Instructions
3+
Any pull requests are welcome, any open issue is fair game, but if you want to be
4+
sure you are doing something useful, please contact one of the core devs.
45

5-
These steps will guide you through contributing to this project:
66

7-
- Fork the repo
8-
- Clone it and install dependencies
9-
10-
git clone https://github.com/YOUR-USERNAME/typescript-library-starter
11-
npm install
12-
13-
Keep in mind that after running `npm install` the git repo is reset. So a good way to cope with this is to have a copy of the folder to push the changes, and the other to try them.
14-
15-
Make and commit your changes. Make sure the commands npm run build and npm run test:prod are working.
16-
17-
Finally send a [GitHub Pull Request](https://github.com/alexjoverm/typescript-library-starter/compare?expand=1) with a clear list of what you've done (read more [about pull requests](https://help.github.com/articles/about-pull-requests/)). Make sure all of your commits are atomic (one feature per commit).
7+
To get started, read the documentation, and especially the docs on
8+
(overview)[./documentation/overview.md] and the docs for
9+
(developers)[./documentation/development.md]

README.md

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
[![Build Status](https://travis-ci.com/daostack/client.svg?token=aXt9zApRNkfx8zDMypWx&branch=master)](https://travis-ci.com/daostack/client)
2+
13
# DAOstack Client
24

3-
The DAOStack Client
4-
* A library to work with the DAOstack ecosystem
5-
* Convenience functions to interact with the DAOstack contracts: vote, stake and execute proposals
6-
* A frontend client library for the [DAOstack subgraph](https://github.com/daostack/subgraph) - search for daos, proposaals
7-
*
5+
The DAOStack Client is a nodejs library to work with the DAOstack ecosystem
6+
* Convenience functions to interact with the [DAOstack contracts](https://github.com/daostack/arc): create proposals, and vote and stake on them
7+
* A client library for the [DAOstack subgraph](https://github.com/daostack/subgraph) - search for daos, proposals
88

9-
[![Build Status](https://travis-ci.com/daostack/client.svg?token=aXt9zApRNkfx8zDMypWx&branch=master)](https://travis-ci.com/daostack/client)
109

1110
## Usage
1211

@@ -23,7 +22,7 @@ import Arc from '@daostack/client'
2322
const arc = new Arc({
2423
graphqlHttpProvider: "https://subgraph.daostack.io/subgraphs/name/v23",
2524
graphqlWsProvider: "wss://ws.subgraph.daostack.io/subgraphs/name/v23",
26-
web3Provider: `wss://mainnet.infura.io/ws/v3/e0cdf3bfda9b468fa908aa6ab03d5ba2`,
25+
web3Provider: `wss://mainnet.infura.io/ws/v3/${YOUR_TOKEN_HERE}`,
2726
ipfsProvider: {
2827
"host": "subgraph.daostack.io",
2928
"port": "443",
@@ -32,45 +31,11 @@ const arc = new Arc({
3231
}
3332
})
3433
// get a list of DAOs
35-
arc.daos()
36-
// before we can use the Arc instance to send transactions, we need to provide it
37-
// with information on where the contracts can be found
38-
// query the subgraph for the contract addresses, and use those
39-
const contractInfos = await arc.fetchContractInfos()
40-
arc.setContractInfo(contractInfos)
41-
34+
arc.daos().subscribe(
35+
(daos) => console.log(`Here are your DAOS: ${daos}`)
36+
)
4237
```
4338

4439
* [overview](./documentation/overview.md)
4540
* [development](./documentation/development.md)
46-
* [example](./documentation/example-session.md)
47-
* [troubleshooting](./documentation/troubleshooting.md)
48-
49-
## Developing
50-
51-
Get all services running:
52-
53-
```sh
54-
docker-compose up graph-node
55-
```
56-
57-
This command will start all the services that are needed for a test environment: a graph-node instance, ganache, IPFS and postgresql.
58-
59-
60-
To run the tests, run:
61-
```sh
62-
npm run test
63-
```
64-
65-
After you are done, run:
66-
```
67-
docker-compose down
68-
```
69-
70-
71-
### Commands
72-
73-
74-
- `npm run build`: Generate bundles and typings, create docs
75-
- `npm run lint`: Lints code
76-
- `npm run test`: run all tests
41+
* [example](./documentation/demo.js) (run with `npm run demo`)

documentation/demo.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* To run this example, you must
3+
* 1. git checkout https://github.com/daostack/client
4+
* 2. npmm install
5+
* 3. npm run build
6+
* 3. docker-compose up -d // this will
7+
* 4. nodejs documentation/example.js
8+
*/
9+
// "Arc" is the main class that handles configuration and connections to various services
10+
11+
async function main() {
12+
13+
console.log('hello!')
14+
15+
// we import fromt he local build of the library (that was created with npm run build)
16+
// but typically, one would do: require('@daostack/client')
17+
const { Arc } = require('../dist/lib/index.js')
18+
// create an Arc instanc with settings to connect to the local docker images
19+
const arc = new Arc({
20+
graphqlHttpProvider: 'http://127.0.0.1:8000/subgraphs/name/daostack',
21+
graphqlHttpMetaProvider: 'http://127.0.0.1:8000/subgraphs',
22+
graphqlWsProvider: 'http://127.0.0.1:8001/subgraphs/name/daostack',
23+
web3Provider: 'ws://127.0.0.1:8545',
24+
ipfsProvider: '/ip4/127.0.0.1/tcp/5001',
25+
})
26+
// we must provice Arc with some contract information. We can either hardcode this, or
27+
// get it from the subgraph
28+
const contractInfos = await arc.fetchContractInfos()
29+
arc.setContractInfos(contractInfos)
30+
31+
// we get the first returned item from the obervable
32+
const { first } = require('rxjs/operators')
33+
const daos = await arc.daos().first()
34+
35+
console.log(`Found ${daos.length} DAOs in ${arc.graphqlHttpProvider}`)
36+
37+
38+
// or if you know the address, just create a new DAO object like this:
39+
const dao = arc.dao(daos[0].id)
40+
41+
// get the DAO state (again, the "first()" object from the observable)
42+
const daoState = await dao.state().first()
43+
// the state contains information such as the address, name or nativeToken of the DAO
44+
console.log(`This DAO has name "${daoState.name}" and is deployed on ${daoState.address}`)
45+
46+
// to create a proposal, we must first find the address of the Scheme to create it in
47+
const schemes = await dao.schemes({ where: { name: 'ContributionReward'}}).pipe(first()).toPromise()
48+
49+
if (schemes.length === 0) {
50+
throw Error('Something went wrong - no ContrsbutsonReward scheme was registered with this DAO')
51+
}
52+
const schemeState = await schemes[0].state().pipe(first()).toPromise()
53+
const schemeAddress = schemeState.address
54+
55+
console.log(`We'll create a ${schemeState.name} proposal at the scheme at ${schemeState.address}`)
56+
57+
// first construct a transaction
58+
const tx = dao.createProposal({
59+
title: 'Demo Proposal',
60+
beneficiary: '0xffcf8fdee72ac11b5c542428b35eef5769c409f0',
61+
ethReward: 300 * 10**18,
62+
nativeTokenReward: 1,
63+
periodLength: 0,
64+
periods: 1,
65+
reputationReward: 10000,
66+
scheme: schemeState.address
67+
})
68+
69+
// now send the transaction - when successful, it will return a Proposal instance
70+
const minedTx = await tx.send()
71+
//
72+
const proposal = minedTx.result
73+
console.log(`created a proposal with id ${proposal.id}`)
74+
console.log(`..... bye!`)
75+
process.exit(0)
76+
}
77+
78+
main()
79+
.catch((err) => { console.log(err); process.exit(0)})

documentation/development.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
# Developing
22

3-
Get all services running:
3+
For development, it is useful to have local instances of Ganache (an ethereum node), IPFS (which is used to store data), an instance of The Graph with the DAOStack subgraph.
4+
The package is provided with convenient docker containers that provide a complete environment for testing and development:
45

6+
Get all services running:
57
```sh
6-
docker-compose up graph-node
8+
docker-compose up
79
```
810

911
This command will build and start a graph instance, ganache, IPFS and postgresql.
1012

11-
Before being able to use these services, you need to deploy the DAOStack contracts and configure the graph node to listen to changes.
12-
Open another terminal and run the following comand:
13-
```sh
14-
npm run setup-env
15-
```
1613

1714
To run the tests, run:
18-
```sh
15+
```
1916
npm run test
2017
```
2118

22-
After you are done, run:
19+
You may also want to run the (demo.js)[./documentation/demo.js] file for some concrete examples of the usage of the library:
2320
```
24-
docker-compose down
21+
npm run demo
2522
```
26-
If you update the subgraph dependency in `package.json`, you must re-configure the graph node:
23+
After you are done, run:
2724
```
28-
npm run setup-env
25+
docker-compose down
2926
```
3027

3128
## Testing
@@ -38,3 +35,9 @@ Or watch:
3835
```sh
3936
npm run test -- --watch
4037
```
38+
39+
### Commands
40+
41+
- `npm run build`: Generate bundles and typings, create docs
42+
- `npm run lint`: Lints code
43+
- `npm run test`: run all tests

documentation/example-session.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)