Skip to content

Commit

Permalink
Merge pull request #2738 from build-5/more-examples
Browse files Browse the repository at this point in the history
Add more examples
  • Loading branch information
adamunchained authored Jan 22, 2024
2 parents 28983bf + 744833d commit ac6f2b8
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 8 deletions.
5 changes: 5 additions & 0 deletions docs/docs/_admonitions/_validate-address.md
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 docs/docs/products/dao-management/member/how-to/get-member.md
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
```
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/>
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ tags:
To create a space, you must call `create` on `dataset(Dataset.SPACE)`. In the body, you can specify the name of the space.
`create` takes an object of type `Build5Request<`[`SpaceCreateRequest`](../../../../search-post/interfaces/SpaceCreateRequest.md)`>` as parameter.

:::info
:::info Create a Member first

To create a space, don't forget to create a member first

:::

```tsx file=../../../../../../packages/sdk/examples/create_space.ts#L11-L26
```tsx file=../../../../../../packages/sdk/examples/space/create.ts#L11-L26
```
24 changes: 24 additions & 0 deletions docs/docs/products/dao-management/space/how-to/update-space.md
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 docs/docs/products/dao-management/space/how-to/validate-address.md
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/>
21 changes: 18 additions & 3 deletions docs/docs/products/nft/how-to/create-nft-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@ tags:
To create a NFT collection, you must call `create` on `dataset(Dataset.NFT_COLLECTION)`. In the body, you can specify the collection's name, the symbol, the base URI, and more.
`create` takes an object of type `Build5Request<`[`CreateCollectionRequest`](../../../search-post/interfaces/CreateCollectionRequest.md)`>` as parameter.

```tsx file=../../../../../packages/sdk/examples/create_nft_collection.ts#L18-L43
```tsx file=../../../../../packages/sdk/examples/create_nft_collection.ts#L18-L42
```
:::tip Space

If you want to add the collection to a space you can just specify it with the `space` property in the `CreateCollectionRequest` object.

:::
:::tip Royalties Space

If you want to specify royality fees you can set the `royaltiesFee` property and specify a `royalitySpace` in the `CreateCollectionRequest` object.

:::
:::info Validated Address in Space

Make sure the `royaltiesSpace`and `space` you specify have a [validated address](../../dao-management/space/how-to/validate-address.md)

:::

After that, you should create a list of objects that describe the single NFTs, their name, description and image, price, and so on.

```tsx file=../../../../../packages/sdk/examples/create_nft_collection.ts#L49-L64
```tsx file=../../../../../packages/sdk/examples/create_nft_collection.ts#L48-L63
```

As a last step, you can mint the batch of NFTs by calling `createBatch` on `dataset(Dataset.NFT)` and passing the list of NFTs in the body.
`createBatch` takes an object of type `Build5Request<`[`NftCreateRequest`](../../../search-post/interfaces/NftCreateRequest.md)`[]>` as parameter.

```tsx file=../../../../../packages/sdk/examples/create_nft_collection.ts#L66-L77
```tsx file=../../../../../packages/sdk/examples/create_nft_collection.ts#L65-L76
```
4 changes: 4 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const sidebars = {
'How To': [
'products/dao-management/member/how-to/create-member',
'products/dao-management/member/how-to/update-member',
'products/dao-management/member/how-to/validate-address',
'products/dao-management/member/how-to/get-member',
],
}
],
Expand All @@ -58,6 +60,8 @@ const sidebars = {
{
'How To': [
'products/dao-management/space/how-to/create-space',
'products/dao-management/space/how-to/update-space',
'products/dao-management/space/how-to/validate-address',
],
}
],
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/examples/create_nft_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async function main() {
'https://images-wen.soonaverse.com/0x551fd2c7c7bf356bac194587dab2fcd46420054b/rrvhjuksm4/fe1105c6-2a66-4496-96d1-ed1625293014.jpeg',
price: 10000000,
royaltiesFee: 0,
royaltiesSpace: '0xdb8902015d244df5d6985b45db089b725713709e',
type: 0,
},
});
Expand Down
41 changes: 41 additions & 0 deletions packages/sdk/examples/member/get.ts
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());
38 changes: 38 additions & 0 deletions packages/sdk/examples/member/validate_address.ts
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());
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dataset, Network, Space } from '@build-5/interfaces';
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk';
import { address } from './utils/secret';
import { walletSign } from './utils/utils';
import { address } from '../utils/secret';
import { walletSign } from '../utils/utils';

async function main() {
const origin = Build5.TEST;
Expand Down
41 changes: 41 additions & 0 deletions packages/sdk/examples/space/update.ts
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());
42 changes: 42 additions & 0 deletions packages/sdk/examples/space/validate_address.ts
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());

0 comments on commit ac6f2b8

Please sign in to comment.