如何使用新的metaplexjs-sdk进行拍卖



我正在构建一个solana市场,并试图从旧的solana市场更新为拍卖行。

代码:


const authority = metaplex.identity();
const auctionHouse = await metaplex
.auctions()
.createAuctionHouse({
sellerFeeBasisPoints: 200,
requiresSignOff: false,
treasuryMint: WRAPPED_SOL_MINT,
authority: authority.publicKey,
canChangeSalePrice: true,
feeWithdrawalDestination: publicKey,
treasuryWithdrawalDestinationOwner: publicKey,
})
.run();



const listNft = async () => {
try {
const NFTs = await metaplex.nfts().findAllByOwner(publicKey).run();
console.log(NFTs[4].mintAddress.toString(), " nft");
const auctionHouse = await metaplex
.auctions()
.findAuctionHouseByCreatorAndMint(publicKey, WRAPPED_SOL_MINT)
.run();
const listtx = metaplex
.auctions()
.builders()
.createListing({
mintAccount: NFTs[4].mintAddress,
price: lamports(1 * LAMPORTS_PER_SOL),
auctionHouse: auctionHouse,
});
var rpcClient = await metaplex.rpc().sendTransaction(listtx);
console.log(rpcClient, "listed nft");
} catch (error) {
console.log(error);
}
};
const getListing = async () => {
const NFTs = await metaplex.nfts().findAllByOwner(publicKey).run();
const retrievedAuctionHouse = await metaplex
.auctions()
.findAuctionHouseByCreatorAndMint(publicKey, WRAPPED_SOL_MINT)
.run();
console.log(retrievedAuctionHouse?.address?.toString(), "auction pubkey");
const retrieveListing = await metaplex
.auctions()
.for(retrievedAuctionHouse)
.findListingByAddress(NFTs[4].mintAddress)
.run();
console.log(retrieveListing, "retrieving listings");
};
const bidNft = async () => {
const NFTs = await metaplex.nfts().findAllByOwner(publicKey).run();
const auctionHouse = await metaplex
.auctions()
.findAuctionHouseByCreatorAndMint(publicKey, WRAPPED_SOL_MINT)
.run();
const { bid, buyerTradeState } = await metaplex
.auctions()
.for(auctionHouse)
.bid({
mintAccount: NFTs[5].mintAddress,
price: lamports(0.5 * LAMPORTS_PER_SOL),
});
console.log(bid, buyerTradeState, "bidding");
};

错误:

尝试列出nft:

MetaplexError:AuctionHouseProgram>帐户已初始化";

来源:程序>拍卖房屋计划[hausS13jsjafwWwGqZTUQRmWyvyxn9EQpqMwV1PBBmk]问题:地址为[hausS13jsjafwWwGqZTUQRmWyvyxn9EQpqMwV1PBBmk]的程序[ActionHouseProgram]引发了代码[1]的错误;帐户已初始化"&";。解决方案:检查程序提供的错误消息。

原因:TokenLendingError#AlreadyInitialized:帐户已初始化">

at RpcClient.parseProgramError (RpcClient.mjs?e98e:206:1)
at RpcClient.sendTransaction (RpcClient.mjs?e98e:48:1)

尝试获取房源时:

Account.js?9f45:47未捕获(承诺中(MetaplexError:找不到账户

来源:SDK问题:在提供的地址[3m117hu6UuV5HjdLmb2GxZkttKTtQ8VseHRCPuUTDJmz]中找不到类型为[ListingReceipt]的帐户。解决方案:确保提供的地址正确,并且此地址存在帐户。

at assertAccountExists (Account.mjs?9f45:47:1)
at eval (Account.mjs?9f45:39:1)
at Object.handle (findListingByAddress.mjs?1810:23:44)
at async eval (Task.mjs?1340:58:1)
at async Disposable.run (Disposable.mjs?b308:22:1)

找到了绕过的方法

  1. 我没有使用metaplex.auction((.builder((.createListing,而是使用了metaplex.auctions((.for(auctionHouse(.list((.

  2. 然后为拍卖费支付者账户提供资金,该账户是一个pda。

  3. 最后在findListingByAddress中,我通过了sellerTradeState

    const { listing, sellerTradeState } = await metaplex
    .auctions()
    .for(auctionHouse)
    .list({
    mintAccount: NFTs[1].mintAddress,
    price: sol(1.5),
    })
    .run();
    

用于获取列出的nft

const retrieveListing = await metaplex
.auctions()
.for(retrievedAuctionHouse)
.findListingByAddress(
sellerTradeState
)
.run();

仅从上面提供的信息来看,就有两个问题:

  1. 您可能已经运行过一次创建拍卖行的createAuctionHouse指令,现在您正在运行同样运行createAuctionHouse指令的listNft函数,它会抛出Account already exists错误。你可以在这里看到为什么会发生这种情况:https://stackoverflow.com/a/72808405/19264629

  2. 您在findListingByAddress指令中使用了NFTs薄荷地址,这是错误的。您必须按照此处所述创建ListingReceipt:https://docs.metaplex.com/guides/auction-house/#auction-房屋收据,同时创建清单本身(这需要在一笔交易中完成(。完成后,您需要在findListingByAddress中插入收据地址来获取列表。

开始工作了。诀窍是为拍卖行提供资金;费用账户";如上所述,在Auction House CLI中:我无法执行销售指令来列出我的NFT

const ah = await mx
.auctionHouse()
.findByAddress({ address:ahKey })
.run();
const nft = await mx
.nfts()
.create({
name:"TESTNFT",
symbol: "TESTNFT",
uri: "https://blah.com",
sellerFeeBasisPoints : 100,
creators: [
{
address: wallet.publicKey,
share: 100,
}]
})
.run();
const price = sol(0.1);
const { listing, sellerTradeState } = await mx
.auctionHouse()
.list({
auctionHouse: ah,
mintAccount: nft.mintAddress,
price
})
.run()

相关内容

  • 没有找到相关文章

最新更新