【问题标题】:Link Asset to solana token将资产链接到 solana 代币
【发布时间】:2021-11-07 11:32:02
【问题描述】:

我有 solana 不可替代代币和资产(图片)。

我想将图像与令牌链接。

我也想创建智能合约但不知道是什么?

有人知道怎么做吗?

【问题讨论】:

  • 不是答案,但这里有一个文档参考。 docs.solana.com/cli/deploy-a-program
  • 智能合约的可能内容是什么
  • 它是用 C、C++ 或 Rust 编写的。除其他外,我相信它包含一个 json 对象,它是定义 Web 服务器上 jpg 链接的位置。
  • 据此,程序包含“指令”。 docs.solana.com/terminology#program
  • 在 Solana 生态系统中,智能合约被称为程序。

标签: cryptography solana


【解决方案1】:

是的,使用区块链 API 非常容易做到这一点。

请参阅their docs 中的“在 Solana 上创建 NFT”端点。

Here 是一些示例(Python、Javascript)。

以下是在 Python 中的操作方法:

pip install theblockchainapi

然后:

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()

【讨论】:

    猜你喜欢
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2022-08-13
    • 2017-11-13
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    相关资源
    最近更新 更多