简体   繁体   English

将资产链接到 solana 令牌

[英]Link Asset to solana token

I have solana non-fungible token and a asset (image).我有 solana 不可替代的代币和资产(图像)。

I want to link image with token.我想将图像与令牌链接。

I also want to create smart contract but don't know what it is ?我也想创建智能合约但不知道它是什么?

Anyone knowns how to do this ?任何人都知道如何做到这一点?

Yes, it's super easy to do this with the Blockchain API.是的,使用区块链 API 做到这一点非常容易。

See the "Create an NFT on Solana" endpoint in their docs .请参阅其文档中的“在 Solana 上创建 NFT”端点。

Here are some examples (Python, Javascript). 以下是一些示例(Python、Javascript)。

Here's how to do it in Python:以下是如何在 Python 中执行此操作:

pip install theblockchainapi

Then:然后:

from theblockchainapi import TheBlockchainAPIResource, SolanaCurrencyUnit

# Get an API key pair for free here: https://dashboard.theblockchainapi.com/
MY_API_KEY_ID = None
MY_API_SECRET_KEY = None
BLOCKCHAIN_API_RESOURCE = TheBlockchainAPIResource(
    api_key_id=MY_API_KEY_ID,
    api_secret_key=MY_API_SECRET_KEY
)


def example():
    """
    This example creates a new wallet, gets an airdrop to mint an NFT, and then mints an NFT.
    """
    try:
        assert MY_API_KEY_ID is not None
        assert MY_API_SECRET_KEY is not None
    except AssertionError:
        raise Exception("Fill in your key ID pair!")

    # Create a wallet
    secret_key = BLOCKCHAIN_API_RESOURCE.generate_secret_key()
    public_key = BLOCKCHAIN_API_RESOURCE.derive_public_key(
        secret_recovery_phrase=secret_key
    )
    print(f"Public Key: {public_key}")
    print(f"Secret Key: {secret_key}")

    # Get an airdrop on the devnet in order to be able to mint an NFT
    BLOCKCHAIN_API_RESOURCE.get_airdrop(public_key)

    # We need to make sure this has time to process before minting the NFT!
    import time
    time.sleep(25)

    def get_balance():
        balance_result = BLOCKCHAIN_API_RESOURCE.get_balance(public_key, unit=SolanaCurrencyUnit.SOL)
        print(f"Balance: {balance_result['balance']}")
    get_balance()

    # Mint an NFT
    nft = BLOCKCHAIN_API_RESOURCE.create_nft(
        secret_recovery_phrase=secret_key,
        nft_name="The Blockchain API",
        nft_symbol="BLOCKX",
        nft_url="https://pbs.twimg.com/profile_images/1441903262509142018/_8mjWhho_400x400.jpg"
    )
    print("NFT: ", nft)
    print(f"You can view the NFT here: {nft['explorer_url']}")


if __name__ == '__main__':
    example()

I want to link image with token.

  1. Upload your image to a service.将您的图像上传到服务。 Here's a good one: https://nft.storage/files/这是一个很好的: https : //nft.storage/files/

  2. Create json file ( https://docs.metaplex.com/nft-standard ).创建 json 文件 ( https://docs.metaplex.com/nft-standard )。 Set uri field to the image link aboveuri字段设置为上面的图片链接

  3. Upload the `json file to a service ( https://docs.metaplex.com/nft-standard ).将 `json 文件上传到服务 ( https://docs.metaplex.com/nft-standard )。

  4. Create a metadata account for your token: It's Program Derived Address (PDA) with a derived key of ['metadata', metadata_program_id, mint_id].为您的令牌创建一个元数据帐户:它是程序派生地址 (PDA),派生密钥为 ['metadata', metadata_program_id, mint_id]。 https://docs.metaplex.com/nft-standard https://docs.metaplex.com/nft-standard

Now you can mint your token to anyone.现在您可以将您的代币铸造给任何人。 They should be able to see that NFT in their wallet.他们应该能够在他们的钱包中看到 NFT。

Here is a sample code I do to create metadata account: https://github.com/batphonghan/minter_machine/blob/dbb1e4cd82f47d5062ca14615f0511d4c8631517/minter_server_actix/src/mint_token.rs#L29这是我创建元数据帐户的示例代码: https : //github.com/batphonghan/minter_machine/blob/dbb1e4cd82f47d5062ca14615f0511d4c8631517/minter_server_actix/src/mint_token.rs#L29

I also want to create smart contract but don't know what it is ? It's an on-chain code called program in solana.这是一个在 solana 中称为 program 的链上代码。 You do not need it to create a metadata account.您不需要它来创建元数据帐户。 Metaplex team has already deployed it. Metaplex 团队已经部署了它。

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

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