External Plugins
Adding External Plugins
Assets
Creating a Core Asset with an External Plugin
Creating a Core Asset with an External Plugin
import { generateSigner } from '@metaplex-foundation/umi'
import { create, CheckResult } from '@metaplex-foundation/mpl-core'
const assetSigner = publicKey('11111111111111111111111111111111')
const oracleAccount = publicKey('22222222222222222222222222222222')
await create(umi, {
asset: assetSigner,
name: 'My Asset',
uri: 'https://example.com/my-asset.json',
plugins: [
{
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
lifecycleChecks: {
update: [CheckResult.CAN_REJECT],
},
baseAddress: oracleAccount,
},
],
}).sendAndConfirm(umi)
Adding a External Plugin to a Core Asset
Adding a Plugin with an assigned authority
use mpl_core::{
instructions::AddExternalPluginAdapterV1Builder,
types::{
ExternalCheckResult, ExternalPluginAdapterInitInfo, HookableLifecycleEvent,
OracleInitInfo, ValidationResultsOffset,
},
};
use solana_client::nonblocking::rpc_client;
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction};
use std::str::FromStr;
pub async fn add_oracle_plugin_to_asset() {
let rpc_client = rpc_client::RpcClient::new("https://api.devnet.solana.com".to_string());
let authority = Keypair::new();
let asset = Pubkey::from_str("11111111111111111111111111111111").unwrap();
let oracle_plugin = Pubkey::from_str("22222222222222222222222222222222").unwrap();
let add_oracle_plugin_to_asset_ix = AddExternalPluginAdapterV1Builder::new()
.asset(asset)
.payer(authority.pubkey())
.init_info(ExternalPluginAdapterInitInfo::Oracle(OracleInitInfo {
base_address: oracle_plugin,
results_offset: Some(ValidationResultsOffset::Anchor),
lifecycle_checks: vec![(
HookableLifecycleEvent::Transfer,
ExternalCheckResult { flags: 4 },
)],
base_address_config: None,
init_plugin_authority: None,
}))
.instruction();
let signers = vec![&authority];
let last_blockhash = rpc_client.get_latest_blockhash().await.unwrap();
let add_oracle_plugin_to_asset_tx = Transaction::new_signed_with_payer(
&[add_oracle_plugin_to_asset_ix],
Some(&authority.pubkey()),
&signers,
last_blockhash,
);
let res = rpc_client
.send_and_confirm_transaction(&add_oracle_plugin_to_asset_tx)
.await
.unwrap();
println!("Signature: {:?}", res)
}
Collections
Creating a Core Collection with an External Plugin
Adding a External Plugin to a Core Collection
import { generateSigner, publicKey } from '@metaplex-foundation/umi'
import { createCollection, CheckResult } from '@metaplex-foundation/core'
const collectionSigner = generateSigner(umi)
const oracleAccount = publicKey('22222222222222222222222222222222')
await createCollection(umi, {
collection: collectionSigner,
name: 'My Collection',
uri: 'https://example.com/my-collection.json',
plugins: [
{
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
lifecycleChecks: {
update: [CheckResult.CAN_REJECT],
},
baseAddress: oracleAccount,
},
,
],
}).sendAndConfirm(umi)
Adding a External Plugin to a Collection
Burning an Assets
import { publicKey } from '@metaplex-foundation/umi'
import { addCollectionPlugin, CheckResult } from '@metaplex-foundation/mpl-core'
const collection = publicKey('11111111111111111111111111111111')
const oracleAccount = publicKey('22222222222222222222222222222222')
await addCollectionPlugin(umi, {
collection: collection,
plugin: {
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
lifecycleChecks: {
update: [CheckResult.CAN_REJECT],
},
baseAddress: oracleAccount,
},
}).sendAndConfirm(umi)