Skip to main content

Update Member

To update a member, we first get the member with their ID, which, in this case, is the member's address.

    const member = await https(origin)
.project(SoonaverseApiKey[Build5.TEST])
.dataset(Dataset.MEMBER)
.id(address.bech32)
.get();

With the member, we can create a signature and update, for example, the name by calling update on dataset(Dataset.MEMBER) and passing the new name in the body. update takes an object of type Build5Request<MemberUpdateRequest> as parameter.

    const response = await https(origin)
.project(SoonaverseApiKey[Build5.TEST])
.dataset(Dataset.MEMBER)
.update({
address: address.bech32,
signature: signature.signature,
publicKey: {
hex: signature.publicKey,
network: Network.RMS,
},
body: {
name: name + '_fun',
},
});

update returns an oject of type Member.

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 {
const member = await https(origin)
.project(SoonaverseApiKey[Build5.TEST])
.dataset(Dataset.MEMBER)
.id(address.bech32)
.get();

const name = Math.random().toString().split('.')[1];
const signature = await walletSign(member.uid, address);
const response = await https(origin)
.project(SoonaverseApiKey[Build5.TEST])
.dataset(Dataset.MEMBER)
.update({
address: address.bech32,
signature: signature.signature,
publicKey: {
hex: signature.publicKey,
network: Network.RMS,
},
body: {
name: name + '_fun',
},
});

console.log('Member updated: ', response);
} catch (error) {
console.error('Error: ', error);
}
}

main().then(() => process.exit());