Update Space
To update a Space, we first as an example get the first space of our member.
// 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];
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
>
as parameter.
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',
},
});
update
returns an oject of type Proposal
.
Full How-To Code
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());