Skip to main content

Bucket

createBucket Storage Provider Tx

Create a new bucket in greenfield. This API sends a request to the storage provider to get approval for creating bucket and sends the createBucket transaction to the Greenfield.

paramsdescription
bucketNamebucket name
creatorcreator account address
visibilityVisibilityType
chargedReadQuotaLongdefines the traffic quota that you read from primary sp
primarySpAddressprimary sp address
paymentAddresspayment address
const tx = await client.bucket.createBucket(
{
bucketName: 'bucket_name',
creator: '0x...',
visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ,
chargedReadQuota: Long.fromString('0'),
primarySpAddress: '0x....',
paymentAddress: address,
}
);

deleteBucket Tx

Send DeleteBucket msg to greenfield chain and return txn hash.

paramsdescription
bucketNameThe name of the bucket to be deleted
operatoroperator account address
const tx = await client.bucket.deleteBucket({
bucketName: bucketName,
operator: address,
});
tip

This is only construct tx, next need simulate and broadcast

deleteBucketPolicy Tx

Delete the bucket policy of the principal.

paramsdescription
operator
bucketNameThe bucket name identifies the bucket
principalAddrPrincipal define the roles that can grant permissions
principalTypePrincipalType refers to the identity type of system users or entities.
const tx = await client.bucket.deleteBucketPolicy(
address,
bucketName,
address,
'PRINCIPAL_TYPE_GNFD_ACCOUNT',
);
tip

This is only construct tx, next need simulate and broadcast

getBucketMeta Storage Provider

This API is used to get bucket meta by bucket name.

paramsdescription
bucketNamebucket name
const bucketInfo = await client.bucket.getBucketMeta({
bucketName: 'bucketName',
});

getBucketPolicy Query

Get the bucket policy info of the user specified by principalAddr.

Browser | Nodejs
import { GRNToString, newBucketGRN } from '@bnb-chain/greenfield-js-sdk';
await client.bucket.getBucketPolicy({
resource: GRNToString(newBucketGRN(bucketName)),
principalAddress: '0x00..',
});

getBucketReadQuota Storage Provider

Query the quota info of the specific bucket of current month.

paramsdescription
bucketNamebucket name
authTypeAuthType
const tx = await client.bucket.getBucketReadQuota(
{
bucketName: 'bucketName',
},
{
type: 'EDDSA',
seed: offChainData.seedString,
domain: window.location.origin,
address,
},
);

headBucket Query

query the bucketInfo on chain, return the bucket info if exists.

paramsdescription
bucketNamebucket name
Browser | Nodejs
const bucketInfo = await client.bucket.headBucket(bucketName);

headBucketById Query

paramsdescription
bucketIdbucket id
Browser | Nodejs
const bucketInfo = await client.bucket.headBucketById(bucketId);

headBucketExtra Query

Queries a bucket extra info (with gvg bindings and price time) with specify name.

paramsdescription
bucketNamebucket name
Browser | Nodejs
const bucketInfo = await client.bucket.headBucketExtra('bucketName');

listBucketReadRecords Storage Provider

List the download record info of the specific bucket of the current month.

paramsdescription
bucketNamebucket name
authTypeAuthType
const tx = await client.bucket.listBucketReadRecords(
{
bucketName: 'bucketName',
startTimeStamp,
endTimeStamp,
maxRecords: 1000,
},
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
);

listBuckets Storage Provider

Lists the bucket info of the user.

paramsdescription
addressuser account
Browser | Nodejs
const res = await client.bucket.listBuckets({
address: '0x...',
});

listBucketsByIds Storage Provider

Lists the bucket info of the user.

paramsdescription
idsbucket ids array
Browser | Nodejs
await client.bucket.listBucketsByIds({
ids: ['1', '2'],
});

listBucketsByPaymentAccount Storage Provider

List bucket info by payment account.

paramsdescription
paymentAccountpayment account address
Browser | Nodejs
const res = await client.bucket.listBucketsByPaymentAccount({
paymentAccount: '0x00...',
});

putBucketPolicy Tx

Apply bucket policy to the principal, return the txn hash.

paramsdescription
bucketNamebucket name
statementsPolicies outline the specific details of permissions, including the Effect, ActionList, and Resources.
principalIndicates the marshaled principal content of greenfield permission types, users can generate it by NewPrincipalWithAccount or NewPrincipalWithGroupId method.
Browser | Nodejs
import { GRNToString, newBucketGRN, PermissionTypes } from '@bnb-chain/greenfield-js-sdk';
const statement: PermissionTypes.Statement = {
effect: PermissionTypes.Effect.EFFECT_ALLOW,
actions: [PermissionTypes.ActionType.ACTION_UPDATE_BUCKET_INFO],
resources: [GRNToString(newBucketGRN(bucketName))],
};
const tx = await client.bucket.putBucketPolicy(bucketName, {
operator: address,
statements: [statement],
principal: {
type: PermissionTypes.PrincipalType.PRINCIPAL_TYPE_GNFD_ACCOUNT,
value: '0x0000000000000000000000000000000000000001',
},
});
tip

This is only construct tx, next need simulate and broadcast

updateBucketInfo Tx

Update the bucket meta on chain, including read quota, payment address or visibility. It will send the MsgUpdateBucketInfo msg to greenfield to update the meta.

paramsdescription
bucketNamebucket name
operatoroperator account address
visibilityVisibilityType
paymentAddresspayment address
chargedReadQuotadefines the traffic quota that you read from primary sp
Browser | Nodejs
await client.bucket.updateBucketInfo({
bucketName: bucketName,
operator: address,
visibility: 1,
paymentAddress: address,
chargedReadQuota: '100',
});
tip

This is only construct tx, next need simulate and broadcast