New!
Core JS SDK v1.0
The V1 Milestone!
Launching the Core JS SDK v1.0 welcomes new improvements to both naming and functionality for devs and end users working with the JS Mpl Core package.
Major Changes
Plugin Constructor Functions
Though while still present in the code base, the new wrappers allow for plugins to be defined without constructor functions.
Auto Generated Kinobi Functions
await createV1(umi, {
asset: assetSigner,
name: 'My Asset',
uri: 'https://example.com/my-asset.json',
plugins: [
{
plugin: createPluginV2({
type: 'Attributes',
attributeList: [{ key: 'key', value: 'value' }],
}),
authority: pluginAuthority('UpdateAuthority'),
},
],
}).sendAndConfirm(umi)
JS SDK v1.0
await create(umi, {
asset: assetSigner,
name: 'My Asset',
uri: 'https://example.com/my-asset.json',
plugins: [
{ type: 'Attributes', attributeList: [{ key: 'key', value: 'value' }] },
],
}).sendAndConfirm(umi)
Plugin Data
Plugin data is elevated to the top level instead of nested under the data field in a plugin object.
Auto Generated Kinobi Functions
await addPluginV1(umi, {
asset: asset.publicKey,
plugin: createPlugin({ type: 'FreezeDelegate', data: { frozen: true } }),
initAuthority: addressPluginAuthority(delegate),
}).sendAndConfirm(umi)
JS SDK v1.0
await addPlugin(umi, {
asset: assetId,
plugin: {
type: 'Attributes',
attributeList: [{ key: 'key', value: 'value' }],
},
}).sendAndConfirm(umi)
Lifecycle Wrapper now Requires Asset Objects
The create/update/transfer/burn now require the full asset/collection objects in order to derive extra accounts (such as external plugin adapter accounts) if any.
Auto Generated Kinobi Functions
const asset = publicKey('11111111111111111111111111111111')
await updateV1(umi, {
asset, // Takes a publicKey
newName: 'New Asset Name',
newUri: 'https://example.com/new-uri',
}).sendAndConfirm(umi)
JS SDK v1.0
const asset = await fetchAssetV1(umi, asset)
await update(umi, {
asset, // Takes the entire Asset object.
name: 'New Asset Name',
uri: 'https://example.com/new-uri',
}).sendAndConfirm(umi)
add/removePlugin and add/removeCollectionPlugin automatically figures out and routes to the right ix based on whether external plugin
The Oracle External Plugin
Support for the Oracle External Plugin is live.
New Improved Helpers
The Core JS SDK v1.0 comes with new and improved helper methods that strip away some of the complexity when dealing with Core Assets/Collections and their data.
Fetch Helpers
The new fetch helpers allows you the option to derive the plugins or not from each helper method.
fetchAsset()
Fetches a single Asset.
const asset = await fetchAsset(umi, assetAddress.publicKey, {
skipDerivePlugins: false,
})
fetchAssetsByOwner()
Fetches all the Assets of a given owners Address.
const assetsByOwner = await fetchAssetsByOwner(umi, owner, {
skipDerivePlugins: false,
})
fetchAssetsByCollection()
Fetches all the Assets of a given Collection Address.
const assetsByCollection = await fetchAssetsByCollection(umi, collection, {
skipDerivePlugins: false,
})
fetchAssetsByUpdateAuthority()
Fetches all the Assets of a given Collection Address.
const assetsByUpdateAuthority = await fetchAssetsByUpdateAuthority(
umi,
updateAuthority,
{ skipDerivePlugins: false }
)
Authority Helpers
The Authority helpers allow you to pass in a publicKey
to check with that the address has the authority over certain aspects of the Core ecosystem (Assets, Collections, and Plugins).
hasPluginAddressAuthority()
The hasPluginAddressAuthority()
returns a boolean
value based on whether the plugin passed in its authority set to an Address
type and the pubkey
matches.
export function hasPluginAddressAuthority(
pubkey: PublicKey | string,
authority: BasePluginAuthority
)
hasPluginOwnerAuthority()
The hasPluginOwnerAuthority()
returns a boolean
value based on whether the plugin passed in its authority set to an Owner
type and the pubkey
matches.
export function hasPluginOwnerAuthority(
pubkey: PublicKey | string,
authority: BasePluginAuthority,
asset: AssetV1
)
hasPluginUpdateAuthority()
The hasPluginUpdateAuthority()
returns a boolean
value based on whether the plugin passed in its authority set to an UpdateAuthority
type and the pubkey
matches.
export function hasPluginUpdateAuthority(
pubkey: PublicKey | string,
authority: BasePluginAuthority,
asset: AssetV1,
collection?: CollectionV1
)
hasAssetUpdateAuthority()
The hasAssetUpdateAuthority()
returns a boolean
value based on whether the passed in pubkey
holds update authority over the Asset.
export function hasAssetUpdateAuthority(
pubkey: string | PublicKey,
asset: AssetV1,
collection?: CollectionV1
)
hasCollectionUpdateAuthority()
The hasCollectionUpdateAuthority()
returns a boolean
value based on whether the passed in pubkey
holds update authority over the Collection.
export function hasCollectionUpdateAuthority(
pubkey: string | PublicKey,
collection: CollectionV1
)
Lifecycle Helpers
The Lifecycle Helpers provide a quick and efficient way to check whether an address can perform a certain lifecycle event.
validateTransfer()
Returns a boolean
value on whether the publicKey is eligible to transfer the Asset.
export async function validateTransfer(
umi,
{ authority, asset, collection, recipient }
)
validateBurn()
Returns a boolean
value on whether the publicKey can burn the Asset.
export async function validateBurn(umi, { authority, asset, collection })
validateUpdate()
Returns a boolean
value on whether the publicKey is eligible to update Asset.
export async function validateUpdate(
umi,
{ authority, asset, collection }
)
Plugin Helpers
assetPluginKeyFromType()
Convert a plugin type to a key for the asset plugins.
export function assetPluginKeyFromType(pluginType: PluginType)
pluginTypeFromAssetPluginKey()
Convert a plugin key to a type.
export function pluginTypeFromAssetPluginKey(key: AssetPluginKey)
checkPluginAuthorities()
Check the authority for the given plugin types on an asset.
export function checkPluginAuthorities({
authority,
pluginTypes,
asset,
collection,
})
State Helpers
collectionAddress()
Find the collection address for the given asset if it is part of a collection. Returns either a publicKey | undefined
export function collectionAddress(asset: AssetV1)
deriveAssetPlugins()
Derive the asset plugins from the asset and collection. Plugins on the asset take precedence over plugins on the collection.
export function deriveAssetPlugins(asset: AssetV1, collection?: CollectionV1)
isFrozen()
Returns a boolean
on whether the Asset is frozen.
export function isFrozen(asset: AssetV1, collection?: CollectionV1)