Просмотр исходного кода

Merge pull request #387 from metaplex-foundation/core/update-asset-collection-fix

fix asset collection update
Tony Boyle 3 месяцев назад
Родитель
Сommit
f2f1a00635
1 измененных файлов с 16 добавлено и 7 удалено
  1. 16 7
      src/pages/core/update.md

+ 16 - 7
src/pages/core/update.md

@@ -124,22 +124,31 @@ import {
   update,
   fetchAsset,
   fetchCollection,
-  updateAuthority,
+  collectionAddress,
+  updateAuthority
 } from "@metaplex-foundation/mpl-core";
 
 const assetId = publicKey("11111111111111111111111111111111");
+
 const asset = await fetchAsset(umi, assetId);
-const oldCollectionId = publicKey("22222222222222222222222222222222");
-const collection = await fetchCollection(umi, oldCollectionId);
-const newCollectionId = publicKey("33333333333333333333333333333333");
+
+const collectionId = collectionAddress(asset)
+
+if (!collectionId) {
+  console.log("Collection not found");
+  return;
+}
+
+const collection = await fetchCollection(umi, collectionId);
+
+const newCollectionId = publicKey("22222222222222222222222222222222")
 
 const updateTx = await update(umi, {
   asset,
-  name: "Updated Asset",
   collection,
-  newUpdateAuthority: updateAuthority("Collection", [newCollectionId]),
+  newCollection: newCollectionId,
+  newUpdateAuthority: updateAuthority('Collection', [newCollectionId]),
 }).sendAndConfirm(umi);
-
 ```
 
 {% /dialect %}