I have solana non-fungible token and a asset (image).
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 ?
I have solana non-fungible token and a asset (image).
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 ?
I want to link image with token.
Upload your image to a service. Here's a good one: https://nft.storage/files/
Create json file (https://docs.metaplex.com/nft-standard). Set uri field to the image link above
Upload the `json file to a service (https://docs.metaplex.com/nft-standard).
Create a metadata account for your token: It's Program Derived Address (PDA) with a derived key of ['metadata', metadata_program_id, mint_id]. 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.
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
I also want to create smart contract but don't know what it is ?
It's an on-chain code called program in solana. You do not need it to create a metadata account. Metaplex team has already deployed it.
Yes, it's super easy to do this with the Blockchain API.
See the "Create an NFT on Solana" endpoint in their docs.
Here are some examples (Python, Javascript).
Here's how to do it in 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()