Skip to main content

Group

createGroup Tx

Create a new group without group members on Greenfield blockchain, and group members can be added by updateGroupMember transaction.

A Group is a collection of accounts that share the same permissions, allowing them to be handled as a single entity.

Examples of permissions include:

  • Put, List, Get, Delete, Copy, and Execute data objects;
  • Create, Delete, and List buckets
  • Create, Delete, ListMembers, Leave groups
  • Create, Associate payment accounts
  • Grant, Revoke the above permissions

For more details regarding Group, please refer to permisson.

paramsdescription
creatorthe account address of group owner who create the group
groupNamethe name of the group. it's not globally unique
extraextra info for the group
example
const tx = await client.group.createGroup({
creator: '0x00..',
groupName: 'group_name',
extra: 'extra_info',
});
tip

This is only construct tx, next need simulate and broadcast

deleteGroup Tx

Delete a group on Greenfield blockchain. The sender MUST only be the group owner, group members or others would fail to send this transaction.

warning

Deleting a group will result in granted permission revoked. Members within the group will no longer have access to resources (bucket, object) which granted permission on.

paramsdescription
operatorthe account address of the operator who has the DeleteGroup permission of the group to be deleted
groupNamethe name of the group which to be deleted
example
const tx = await client.group.deleteGroup({
groupName: 'group_name',
operator: '0x00..',
});
tip

This is only construct tx, next need simulate and broadcast

getBucketPolicyOfGroup Query

Queries a bucket of policy that grants permission to a group.

paramsdescription
bucketNamebucket name
groupIdgroup id
example
await client.group.getBucketPolicyOfGroup('bucket_name', 1);

getObjectPolicyOfGroup Query

Queries a object of policy that grants permission to a group.

paramsdescription
bucketNamebucket name
objectNameobject name
groupIdgroup id
example
await client.group.getObjectPolicyOfGroup('bucket_name', 'object_name', 1);

headGroup Query

Query the groupInfo on chain, return the group info if exists.

paramsdescription
groupNamegroup name
groupOwnerowner of group
example
await client.group.headGroup('group_name', '0x00..');

headGroupMember Query

Query the group member info on chain, return true if the member exists in group.

paramsdescription
groupNamegroup name
groupOwnerowner of group
membermember of group
example
await client.group.headGroupMember(
'groupName',
'0x00..',
'0x903904936a4328fac5477c0d96acf2E2bCaCD33d',
);

leaveGroup Tx

Leave a group. A group member initially leaves a group.

paramsdescription
addressoperator address
memberthe account address of the member who want to leave the group
groupOwnerthe owner of the group you want to leave
groupNamethe name of the group you want to leave
example
await client.group.leaveGroup(
'0x...', // address
{
member: '0x...',
groupOwner: '0x...',
groupName: 'group_name',
},
);
tip

This is only construct tx, next need simulate and broadcast

putGroupPolicy Tx

Apply group policy to user specified by principalAddr, the sender needs to be the owner of the group.

paramsdescription
ownerowner of group
groupNamename of group
example
import { PermissionTypes } from '@bnb-chain/greenfield-js-sdk';
const statement: PermissionTypes.Statement = {
effect: PermissionTypes.Effect.EFFECT_ALLOW,
actions: [PermissionTypes.ActionType.ACTION_UPDATE_GROUP_MEMBER],
resources: [],
};

await client.group.putGroupPolicy(
'0x...', // owner
'group_name',
{
operator: '0x...', // address
statements: [statement],
principal: {
type: PermissionTypes.PrincipalType.PRINCIPAL_TYPE_GNFD_ACCOUNT,
value: '0x0000000000000000000000000000000000000001',
},
},
);
tip

This is only construct tx, next need simulate and broadcast

updateGroupExtra Tx

Update a group extra.

paramsdescription
operatorthe account address of the operator who has the UpdateGroupMember permission of the group
groupOwnerthe account address of the group owner
groupNamethe name of the group which to be updated
extraextra info for the group to update
example
await client.group.updateGroupExtra({
operator: '0x...',
groupOwner: '0x...',
groupName: 'group_name',
extra: 'extra info',
});
tip

This is only construct tx, next need simulate and broadcast

updateGroupMember

Update a group by adding or removing members. The sender can be the group owner or any individual account(Principle) that has been granted permission by the group owner.

paramsdescription
operatorthe account address of the operator who has the UpdateGroupMember permission of the group
groupOwnerthe account address of the group owner
groupNamethe name of the group which to be updated
membersToAddMsgGroupMember[]
membersToDeletestring[]
example
await client.group.updateGroupMember({
operator: '0x..',
groupOwner: '0x..',
groupName: 'group_name',
membersToAdd: [
{
expirationTime: toTimestamp(date),
member: '0x903904936a4328fac5477c0d96acf2E2bCaCD33d',
},
],
membersToDelete: [],
});
tip

This is only construct tx, next need simulate and broadcast