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.
params | description |
---|---|
bucketName | bucket name |
creator | creator account address |
visibility | VisibilityType |
chargedReadQuota | Longdefines the traffic quota that you read from primary sp |
primarySpAddress | primary sp address |
paymentAddress | payment 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.
params | description |
---|---|
bucketName | The name of the bucket to be deleted |
operator | operator account address |
const tx = await client.bucket.deleteBucket({
bucketName: bucketName,
operator: address,
});
deleteBucketPolicy Tx
Delete the bucket policy of the principal.
params | description |
---|---|
operator | |
bucketName | The bucket name identifies the bucket |
principalAddr | Principal define the roles that can grant permissions |
principalType | PrincipalType refers to the identity type of system users or entities. |
const tx = await client.bucket.deleteBucketPolicy(
address,
bucketName,
address,
'PRINCIPAL_TYPE_GNFD_ACCOUNT',
);
getBucketMeta Storage Provider
This API is used to get bucket meta by bucket name.
params | description |
---|---|
bucketName | bucket name |
const bucketInfo = await client.bucket.getBucketMeta({
bucketName: 'bucketName',
});
getBucketPolicy Query
Get the bucket policy info of the user specified by principalAddr.
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.
params | description |
---|---|
bucketName | bucket name |
authType | AuthType |
- Browser
- Nodejs
const tx = await client.bucket.getBucketReadQuota(
{
bucketName: 'bucketName',
},
{
type: 'EDDSA',
seed: offChainData.seedString,
domain: window.location.origin,
address,
},
);
const tx = await client.bucket.getBucketReadQuota(
{
bucketName: 'bucketName',
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
);
headBucket Query
query the bucketInfo on chain, return the bucket info if exists.
params | description |
---|---|
bucketName | bucket name |
const bucketInfo = await client.bucket.headBucket(bucketName);
headBucketById Query
params | description |
---|---|
bucketId | bucket id |
const bucketInfo = await client.bucket.headBucketById(bucketId);
headBucketExtra Query
Queries a bucket extra info (with gvg bindings and price time) with specify name.
params | description |
---|---|
bucketName | bucket name |
const bucketInfo = await client.bucket.headBucketExtra('bucketName');
listBucketReadRecords Storage Provider
List the download record info of the specific bucket of the current month.
params | description |
---|---|
bucketName | bucket name |
authType | AuthType |
- Browser
- Nodejs
const tx = await client.bucket.listBucketReadRecords(
{
bucketName: 'bucketName',
startTimeStamp,
endTimeStamp,
maxRecords: 1000,
},
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
);
const tx = await client.bucket.listBucketReadRecords(
{
bucketName: 'bucketName',
startTimeStamp,
endTimeStamp,
maxRecords: 1000,
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
);
listBuckets Storage Provider
Lists the bucket info of the user.
params | description |
---|---|
address | user account |
const res = await client.bucket.listBuckets({
address: '0x...',
});
listBucketsByIds Storage Provider
Lists the bucket info of the user.
params | description |
---|---|
ids | bucket ids array |
await client.bucket.listBucketsByIds({
ids: ['1', '2'],
});
listBucketsByPaymentAccount Storage Provider
List bucket info by payment account.
params | description |
---|---|
paymentAccount | payment account address |
const res = await client.bucket.listBucketsByPaymentAccount({
paymentAccount: '0x00...',
});
putBucketPolicy Tx
Apply bucket policy to the principal, return the txn hash.
params | description |
---|---|
bucketName | bucket name |
statements | Policies outline the specific details of permissions, including the Effect, ActionList, and Resources. |
principal | Indicates the marshaled principal content of greenfield permission types, users can generate it by NewPrincipalWithAccount or NewPrincipalWithGroupId method. |
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',
},
});
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.
params | description |
---|---|
bucketName | bucket name |
operator | operator account address |
visibility | VisibilityType |
paymentAddress | payment address |
chargedReadQuota | defines the traffic quota that you read from primary sp |
await client.bucket.updateBucketInfo({
bucketName: bucketName,
operator: address,
visibility: 1,
paymentAddress: address,
chargedReadQuota: '100',
});