-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2738 from build-5/more-examples
Add more examples
- Loading branch information
Showing
14 changed files
with
289 additions
and
8 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,5 @@ | ||
:::info Validated Address | ||
|
||
To validate your address you will have to send the requested amount to the target address. This will validate the address you are sending from. | ||
|
||
::: |
48 changes: 48 additions & 0 deletions
48
docs/docs/products/dao-management/member/how-to/get-member.md
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,48 @@ | ||
--- | ||
title: Get Member | ||
tags: | ||
- how-to | ||
- get | ||
- member | ||
--- | ||
|
||
You can use different functions depending on your needs to get one or multiple members. This how-to will list and explain them. | ||
|
||
:::tip Live listeners | ||
|
||
All those functions also have a `Live` function, which returns an `Observable` you can listen to. Just append `Live` to the function name. | ||
|
||
::: | ||
:::tip Pagination | ||
|
||
Most of the functions have an optional `startAfter` parameter. You can use this parameter for pagination. You can pass, for example, the `uid` of the last member you received to get to the next page. | ||
|
||
::: | ||
|
||
## Get By Field | ||
|
||
You need to call `getByField`. `getByField` takes a `string` as `fieldName` and the value you want to look for as `fieldValue`. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/member/get.ts#L9-L12 | ||
``` | ||
|
||
## Get By Space | ||
|
||
You need to call `getBySpace`. `getBySpace` takes a `string` as `space` id. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/member/get.ts#L16-L19 | ||
``` | ||
|
||
## Get All Updated After | ||
|
||
You need to call `getAllUpdatedAfter`. `getAllUpdatedAfter` takes a unix timestamp. The results will contain all members updated after this timestamp. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/member/get.ts#L23-L26 | ||
``` | ||
|
||
## Get Many By Id | ||
|
||
You need to call `getManyById`. `getManyById` takes a list of IDs as `string`. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/member/get.ts#L31-L34 | ||
``` |
12 changes: 12 additions & 0 deletions
12
docs/docs/products/dao-management/member/how-to/validate-address.md
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,12 @@ | ||
--- | ||
title: Validate Space Address | ||
--- | ||
|
||
To validate the address of a member, you must call `validateAddress` on `dataset(Dataset.MEMBER)`. `validateAddress` takes an object of type `Build5Request<`[`AddressValidationRequest`](../../../../search-post/interfaces/AddressValidationRequest.md)`>` as parameter. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/member/validate_address.ts#L16-L30 | ||
``` | ||
|
||
import ValidateAddress from '../../../../_admonitions/_validate-address.md'; | ||
|
||
<ValidateAddress/> |
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
24 changes: 24 additions & 0 deletions
24
docs/docs/products/dao-management/space/how-to/update-space.md
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,24 @@ | ||
--- | ||
title: Update Space | ||
keywords: | ||
- how-to | ||
- update | ||
- space | ||
--- | ||
|
||
To update a Space, we first as an example get the first space of our member. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/space/update.ts#L9-L15 | ||
``` | ||
|
||
:::info Update a Space as Guardian | ||
|
||
You can only update Spaces where you are a Guardian | ||
|
||
::: | ||
|
||
With the space ID and Guardian member we can create a signature and update, for example, the name by calling `update` on `dataset(Dataset.SPACE)` and passing the new name in the body. | ||
`update` takes an object of type `Build5Request<`[`SpaceUpdateRequest`](../../../../search-post/interfaces/SpaceUpdateRequest.md)`>` as parameter. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/space/update.ts#L19-L33 | ||
``` |
12 changes: 12 additions & 0 deletions
12
docs/docs/products/dao-management/space/how-to/validate-address.md
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,12 @@ | ||
--- | ||
title: Validate Space Address | ||
--- | ||
|
||
To validate the address of a space, you must call `validateAddress` on `dataset(Dataset.SPACE)`. `validateAddress` takes an object of type `Build5Request<`[`AddressValidationRequest`](../../../../search-post/interfaces/AddressValidationRequest.md)`>` as parameter in wich you can specify the name of the space. | ||
|
||
```tsx file=../../../../../../packages/sdk/examples/space/validate_address.ts#L19-L33 | ||
``` | ||
|
||
import ValidateAddress from '../../../../_admonitions/_validate-address.md'; | ||
|
||
<ValidateAddress/> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Dataset, Member } from '@build-5/interfaces'; | ||
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk'; | ||
|
||
async function main() { | ||
const origin = Build5.TEST; | ||
try { | ||
var members: Member[]; | ||
const name = 'Santa Claus'; | ||
members = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.getByField('name', name); | ||
console.log('Members with name', name, ':', members.length); | ||
|
||
const space_id = '0x6355fbcc70c6498d0e86d729956686935746980a'; | ||
members = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.getBySpace(space_id); | ||
console.log('Members in space ', space_id, ':', members.length); | ||
|
||
const updatedAfter = 1705276800; | ||
members = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.getAllUpdatedAfter(updatedAfter); | ||
console.log('Members updated after ', new Date(updatedAfter * 1000), ':', members.length); | ||
|
||
// Let's get some member ids | ||
const member_ids = members.map((member) => member.uid).slice(members.length - 2); | ||
members = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.getManyById(member_ids); | ||
console.log('Members by id: ', members.length); | ||
} catch (error) { | ||
console.error('Error: ', error); | ||
} | ||
} | ||
|
||
main().then(() => process.exit()); |
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,38 @@ | ||
import { Dataset, Network } from '@build-5/interfaces'; | ||
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk'; | ||
import { address } from '../utils/secret'; | ||
import { walletSign } from '../utils/utils'; | ||
|
||
async function main() { | ||
try { | ||
const origin = Build5.TEST; | ||
const member = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.id(address.bech32) | ||
.get(); | ||
|
||
const signature = await walletSign(member.uid, address); | ||
const response = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.SPACE) | ||
.validateAddress({ | ||
address: address.bech32, | ||
signature: signature.signature, | ||
publicKey: { | ||
hex: signature.publicKey, | ||
network: Network.RMS, | ||
}, | ||
body: { | ||
network: 'rms', | ||
}, | ||
}); | ||
|
||
console.log('Address validation request send: ', response); | ||
console.log(`Please send ${response.payload.amount} to ${response.payload.targetAddress}.`); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
main().then(() => process.exit()); |
4 changes: 2 additions & 2 deletions
4
packages/sdk/examples/create_space.ts → packages/sdk/examples/space/create.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Dataset, Network } from '@build-5/interfaces'; | ||
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk'; | ||
import { address } from '../utils/secret'; | ||
import { walletSign } from '../utils/utils'; | ||
|
||
async function main() { | ||
const origin = Build5.TEST; | ||
try { | ||
// Get the first space of our member and let's hope we are a guardian there as this is needed to update the space | ||
const member = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.id(address.bech32) | ||
.get(); | ||
const space = Object.values(member.spaces)[0]; | ||
|
||
const name = Math.random().toString().split('.')[1]; | ||
const signature = await walletSign(address.bech32, address); | ||
const response = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.SPACE) | ||
.update({ | ||
address: address.bech32, | ||
signature: signature.signature, | ||
publicKey: { | ||
hex: signature.publicKey, | ||
network: Network.RMS, | ||
}, | ||
body: { | ||
uid: space.uid, | ||
name: name + '_fun', | ||
}, | ||
}); | ||
|
||
console.log('Space updated: ', response); | ||
} catch (error) { | ||
console.error('Error: ', error); | ||
} | ||
} | ||
|
||
main().then(() => process.exit()); |
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,42 @@ | ||
import { Dataset, Network } from '@build-5/interfaces'; | ||
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk'; | ||
import { address } from '../utils/secret'; | ||
import { walletSign } from '../utils/utils'; | ||
|
||
async function main() { | ||
try { | ||
const origin = Build5.TEST; | ||
|
||
// Get the first space of our member and let's hope we are a guardian there as this is needed to update the space | ||
const member = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.MEMBER) | ||
.id(address.bech32) | ||
.get(); | ||
const space = Object.values(member.spaces)[0]; | ||
|
||
const signature = await walletSign(member.uid, address); | ||
const response = await https(origin) | ||
.project(SoonaverseApiKey[Build5.TEST]) | ||
.dataset(Dataset.SPACE) | ||
.validateAddress({ | ||
address: address.bech32, | ||
signature: signature.signature, | ||
publicKey: { | ||
hex: signature.publicKey, | ||
network: Network.RMS, | ||
}, | ||
body: { | ||
network: 'rms', | ||
space: space.uid, | ||
}, | ||
}); | ||
|
||
console.log('Address validation request send: ', response); | ||
console.log(`Please send ${response.payload.amount} to ${response.payload.targetAddress}.`); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
main().then(() => process.exit()); |