Creators
The Creators
extension allows adding a list of creators to an asset, specifying their status (verified
or not) and a percentage share. In most cases, this extension is used in combination with Royalties
to determine the addresses that should received royalties. There is no limit on how many creators can be added to an asset.
The extension consists of a list of Creator
s:
Field | Description | |
---|---|---|
values[0..n] | List of Creator objects. | |
Each Creator object is represented by: | ||
address | Address of the creator. | |
verified | Indicates if the creator is verified or not. | |
share | Percentage share of the royalties (between 0 and 100 ). |
Adding Creators
The Creators
extension can be created using either the allocate
, create
or update
instructions.
- JavaScript
- Rust
- Rust (on-chain)
import { allocate, creators } from '@nifty-oss/asset';
const creator1 = publicKey("...");
const creator2 = publicKey("...");
await allocate(umi, {
asset,
payer,
extension: creators([
{ address: creator1, share: 50 },
{ address: creator2, share: 50 }
]),
}).sendAndConfirm(umi);
use nifty_asset::{
extensions::{CreatorsBuilder, ExtensionBuilder},
instructions::AllocateBuilder,
types::{ExtensionInput, ExtensionType},
};
use solana_progra::pubkey::Pubkey;
let creator1 = Pubkey::default();
let creator2 = Pubkey::default();
let mut creators = CreatorsBuilder::default();
creators.add(&creator1, 50);
creators.add(&creator2, 50);
let ix = AllocateBuilder::new()
.asset(asset.pubkey())
.payer(Some(payer.pubkey()))
.system_program(Some(system_program::id()))
.extension(ExtensionInput {
extension_type: ExtensionType::Creators,
length: creators.len() as u32,
data: Some(creators),
})
.instruction();
use nifty_asset::{
extensions::{Attributes, AllocateCpiBuilder, ExtensionBuilder},
instructions::AllocateBuilder,
types::{ExtensionInput, ExtensionType},
};
use solana_progra::pubkey::Pubkey;
let creator1 = Pubkey::default();
let creator2 = Pubkey::default();
let mut creators = CreatorsBuilder::default();
creators.add(&creator1, 50);
creators.add(&creator2, 50);
AllocateCpiBuilder::new(ctx.accounts.nifty_asset_program)
.asset(ctx.accounts.group)
.payer(Some(ctx.accounts.payer))
.system_program(Some(ctx.accounts.system_program))
.extension(ExtensionInput {
extension_type: ExtensionType::Creators,
length: creators.len() as u32,
data: Some(creators),
})
.invoke();
Fetching Creators
Given an asset account, it is possible to retrieve the creators of an asset. Note that not all assets might have the extension, therefore it is necessary to assert if the extension was found.
- JavaScript
- Rust
- Rust (on-chain)
import {
ExtensionType,
fetchAsset,
getExtension
} from '@nifty-oss/asset';
const asset = await fetchAsset(umi, address);
const creators = getExtension(asset, ExtensionType.Creators);
if (creators) {
creators.values.forEach(({ address, share }) => {
console.log(address + '=' + share);
});
}
use nifty_asset::{
extensions::Creators,
state::Asset,
};
let account = get_account(address)
.await
.unwrap();
let account_data = account.data.as_ref();
if let Some(creators) = Asset::get::<Creators>(account_data) {
println!("creators: {:?}", creators);
}
use nifty_asset::{
extensions::Attributes,
state::Asset,
};
let data = (*ctx.accounts.asset.data).borrow();
if let Some(creators) = Asset::get::<Creators>(&data) {
msg!("creators: {:?}", creators);
}