diff --git a/docs/docs/_admonitions/_validate-address.md b/docs/docs/_admonitions/_validate-address.md new file mode 100644 index 0000000000..a82c56ff9e --- /dev/null +++ b/docs/docs/_admonitions/_validate-address.md @@ -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. + +::: \ No newline at end of file diff --git a/docs/docs/products/dao-management/member/how-to/get-member.md b/docs/docs/products/dao-management/member/how-to/get-member.md new file mode 100644 index 0000000000..46de3bf9fd --- /dev/null +++ b/docs/docs/products/dao-management/member/how-to/get-member.md @@ -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 +``` diff --git a/docs/docs/products/dao-management/member/how-to/validate-address.md b/docs/docs/products/dao-management/member/how-to/validate-address.md new file mode 100644 index 0000000000..f0a8904c57 --- /dev/null +++ b/docs/docs/products/dao-management/member/how-to/validate-address.md @@ -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'; + + diff --git a/docs/docs/products/dao-management/space/how-to/create-space.md b/docs/docs/products/dao-management/space/how-to/create-space.md index 9610b7f780..70f601f857 100644 --- a/docs/docs/products/dao-management/space/how-to/create-space.md +++ b/docs/docs/products/dao-management/space/how-to/create-space.md @@ -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 ``` diff --git a/docs/docs/products/dao-management/space/how-to/update-space.md b/docs/docs/products/dao-management/space/how-to/update-space.md new file mode 100644 index 0000000000..3187b133ca --- /dev/null +++ b/docs/docs/products/dao-management/space/how-to/update-space.md @@ -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 +``` diff --git a/docs/docs/products/dao-management/space/how-to/validate-address.md b/docs/docs/products/dao-management/space/how-to/validate-address.md new file mode 100644 index 0000000000..f5bf615eff --- /dev/null +++ b/docs/docs/products/dao-management/space/how-to/validate-address.md @@ -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'; + + diff --git a/docs/docs/products/nft/how-to/create-nft-collection.md b/docs/docs/products/nft/how-to/create-nft-collection.md index 4afba27587..0f611c8ee4 100644 --- a/docs/docs/products/nft/how-to/create-nft-collection.md +++ b/docs/docs/products/nft/how-to/create-nft-collection.md @@ -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 ``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 79c809d26f..e7affde2bf 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -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', ], } ], @@ -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', ], } ], diff --git a/packages/sdk/examples/create_nft_collection.ts b/packages/sdk/examples/create_nft_collection.ts index 502650930c..003d68dbc6 100644 --- a/packages/sdk/examples/create_nft_collection.ts +++ b/packages/sdk/examples/create_nft_collection.ts @@ -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, }, }); diff --git a/packages/sdk/examples/member/get.ts b/packages/sdk/examples/member/get.ts new file mode 100644 index 0000000000..2fdd9206b2 --- /dev/null +++ b/packages/sdk/examples/member/get.ts @@ -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()); diff --git a/packages/sdk/examples/member/validate_address.ts b/packages/sdk/examples/member/validate_address.ts new file mode 100644 index 0000000000..1d6dd69190 --- /dev/null +++ b/packages/sdk/examples/member/validate_address.ts @@ -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()); diff --git a/packages/sdk/examples/create_space.ts b/packages/sdk/examples/space/create.ts similarity index 90% rename from packages/sdk/examples/create_space.ts rename to packages/sdk/examples/space/create.ts index 76bc7c7ea0..2aed9d2f29 100644 --- a/packages/sdk/examples/create_space.ts +++ b/packages/sdk/examples/space/create.ts @@ -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; diff --git a/packages/sdk/examples/space/update.ts b/packages/sdk/examples/space/update.ts new file mode 100644 index 0000000000..e7a78edfc6 --- /dev/null +++ b/packages/sdk/examples/space/update.ts @@ -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()); diff --git a/packages/sdk/examples/space/validate_address.ts b/packages/sdk/examples/space/validate_address.ts new file mode 100644 index 0000000000..87b4210afa --- /dev/null +++ b/packages/sdk/examples/space/validate_address.ts @@ -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());