简体   繁体   English

如何使用糖果机创建的NFT获取糖果机ID?

[英]How to get the candy machine ID using a NFT created by the candy machine?

Suppose I only have the mint address of a single NFT created by a specific candy machine.假设我只有特定糖果机创建的单个 NFT 的铸币地址。 How can I use the mint address and ultimately get the candy machine ID?如何使用铸币地址最终得到糖果机ID? is it even possible?有可能吗?

A fast way to get the CMid using an NFT is fetching the first tx that the NFT has (the oldest one) and checking the fifth instruction, then the first account on this instruction is the Candy Machine used to create and mint the NFT.使用 NFT 获取 CMid 的一种快速方法是获取 NFT 拥有的第一个 tx(最旧的一个)并检查第五条指令,然后该指令的第一个帐户是用于创建和铸造 NFT 的糖果机。

For example lets take this NFT 3GXHJJd1DfEn1PVip87uUJXjeW1jDgeJb3B7a6xHWAeJ , the oldest transaction that is has is this one .例如,让我们以这个 NFT 3GXHJJd1DfEn1PVip87uUJXjeW1jDgeJb3B7a6xHWAeJ ,最早的交易就是这个 Then you can see on the image below that the first account on the 5th instruction is: H2oYLkXdkX38eQ6VTqs26KAWAvEpYEiCtLt4knEUJxpu (Note that this CM account is empty because they withdraw and close the account after mint).然后你可以在下图中看到第5条指令的第一个账户是: H2oYLkXdkX38eQ6VTqs26KAWAvEpYEiCtLt4knEUJxpu (注意这个CM账户是空的,因为他们在铸币后退出并关闭了账户)。

来自具有 id 的 NFT 的最旧 tx 的第五条指令示例:3GXHJJd1DfEn1PVip87uUJXjeW1jDgeJb3B7a6xHWAeJ

You can do it using some explorer of with code using solana/web3.js您可以使用一些使用solana/web3.js的代码资源管理器来完成

as per the official documentation: https://docs.metaplex.com/guides/mint-lists根据官方文档: https://docs.metaplex.com/guides/mint-lists

The typical method to create the mint list is to a use a tool that finds all NFTs with a specific creator in the first position of the creators array.创建造币厂列表的典型方法是使用一种工具,在创建者数组的第一个 position 中找到具有特定创建者的所有 NFT。 If your NFTs were minted with a candy machine this will be the candy machine creator id by default.如果您的 NFT 是用糖果机铸造的,默认情况下这将是糖果机创建者 ID。 If you have multiple candy machines that are part of the collection, you can create a separate mint list for each candy machine and combine them together to create a single mint list which you provide to the marketplace(s) you are listing with.如果您有多个属于该系列的糖果机,您可以为每个糖果机创建一个单独的薄荷列表,并将它们组合在一起以创建一个薄荷列表,您可以将该列表提供给您所列出的市场。

And how to get the creators from a mint address is by getting the metadata associated with the mint address.而如何从铸币地址获取创作者是通过获取与铸币地址关联的元数据。

The metadata is encoded in a specific format for which you can use the metaplex libraries to decode.元数据以特定格式编码,您可以使用 metaplex 库对其进行解码。 Here is a simple python example: https://github.com/michaelhly/solana-py/issues/48#issuecomment-1073077165这是一个简单的 python 示例: https://github.com/michaelhly/solana-py/issues/48#issuecomment-1073077165

def unpack_metadata_account(data):
    assert(data[0] == 4)
    i = 1
    source_account = base58.b58encode(bytes(struct.unpack('<' + "B"*32, data[i:i+32])))
    i += 32
    mint_account = base58.b58encode(bytes(struct.unpack('<' + "B"*32, data[i:i+32])))
    i += 32
    name_len = struct.unpack('<I', data[i:i+4])[0]
    i += 4
    name = struct.unpack('<' + "B"*name_len, data[i:i+name_len])
    i += name_len
    symbol_len = struct.unpack('<I', data[i:i+4])[0]
    i += 4
    symbol = struct.unpack('<' + "B"*symbol_len, data[i:i+symbol_len])
    i += symbol_len
    uri_len = struct.unpack('<I', data[i:i+4])[0]
    i += 4
    uri = struct.unpack('<' + "B"*uri_len, data[i:i+uri_len])
    i += uri_len
    fee = struct.unpack('<h', data[i:i+2])[0]
    i += 2
    has_creator = data[i]
    i += 1
    creators = []
    verified = []
    share = []
    if has_creator:
        creator_len = struct.unpack('<I', data[i:i+4])[0]
        i += 4
        for _ in range(creator_len):
            creator = base58.b58encode(bytes(struct.unpack('<' + "B"*32, data[i:i+32])))
            creators.append(creator)
            i += 32
            verified.append(data[i])
            i += 1
            share.append(data[i])
            i += 1
    primary_sale_happened = bool(data[i])
    i += 1
    is_mutable = bool(data[i])
    metadata = {
        "update_authority": source_account,
        "mint": mint_account,
        "data": {
            "name": bytes(name).decode("utf-8").strip("\x00"),
            "symbol": bytes(symbol).decode("utf-8").strip("\x00"),
            "uri": bytes(uri).decode("utf-8").strip("\x00"),
            "seller_fee_basis_points": fee,
            "creators": creators,
            "verified": verified,
            "share": share,
        },
        "primary_sale_happened": primary_sale_happened,
        "is_mutable": is_mutable,
    }
    return metadata

and

METADATA_PROGRAM_ID = PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s')
def get_nft_pda(mint_key):
    return(PublicKey.find_program_address([b'metadata', bytes(METADATA_PROGRAM_ID), bytes(PublicKey(mint_key))],METADATA_PROGRAM_ID)[0])
def get_metadata(mint_key):
    data = base64.b64decode(solana_client.get_account_info(get_nft_pda(mint_key))['result']['value']['data'][0])
    return(unpack_metadata_account(data))

An example getting Candy Machine ID using this method for the " Aw4RhpcW5rod2Afhp7dhv2XrMZyNJpzVdYkjJ7kkYzpS " mint address would result in:使用此方法获取“ Aw4RhpcW5rod2Afhp7dhv2XrMZyNJpzVdYkjJ7kkYzpS ”铸币地址的糖果机器 ID 的示例将导致:

    "update_authority": "DGNZDSvy6emDXvBuCDRrpLVxcPaEcvKiStvvCivEJ38X",
    "mint": "Aw4RhpcW5rod2Afhp7dhv2XrMZyNJpzVdYkjJ7kkYzpS",
    "data": {
        "name": "Shadowy Super Coder #5240",
        "symbol": "SSC",
        "uri": "https://shdw-drive.genesysgo.net/8yHTE5Cz3hwcTdghynB2jgLuvKyRgKEz2n5XvSiXQabG/5240.json",
        "seller_fee_basis_points": 500,
        "creators": [
            "71ghWqucipW661X4ht61qvmc3xKQGMBGZxwSDmZrYQmf",
            "D6wZ5U9onMC578mrKMp5PZtfyc5262426qKsYJW7nT3p"
        ],
        "verified": [
            1,
            0
        ],
        "share": [
            0,
            100
        ]
    },
    "primary_sale_happened": true,
    "is_mutable": true
}

In this case, for the Collection SSC, the candy machine ID is 71ghWqucipW661X4ht61qvmc3xKQGMBGZxwSDmZrYQmf在这种情况下,对于 Collection SSC,糖果机 ID 为71ghWqucipW661X4ht61qvmc3xKQGMBGZxwSDmZrYQmf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM