Coder Social home page Coder Social logo

python-api's Introduction

Metaplex Python API

This modules allows you to create, mint, transfer and burn NFTs on the Solana blockchain using Python.

Setup

First, clone down the repository

Create a virtual environment and install the dependencies in requirements.txt. Be sure to use a version of Python >= 3.6

python3 -m virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

At this point, you should be good to go.

Usage

To create a MetaplexAPI object, you need to pass a dicitonary to the constructor with the following keys:

cfg = {
    "PRIVATE_KEY": YOUR_PRIVATE_KEY,
    "PUBLIC_KEY": YOUR_PUBLIC_KEY,
    "DECRYPTION_KEY": SERVER_DECRYPTION_KEY
}
api = MetaplexAPI(cfg)

The keypair that is passed into the MetaplexAPI serves as the fee payer for all network transactions (creating new wallets, minting tokens, transferring tokens, etc). Both keys are base58 encoded.

The decryption key ensures that messages sent to a server that utilizes this API will not be receiving unencrypted private keys over the wire. These private keys are necessary for signing transactions. The client can encrypt their data by using the same decryption key as the server. This is the syntax:

from cryptography.fernet import Fernet
cipher = Fernet(DECRYPTION_KEY) # This is the same key that the server has
encrypted_key = cipher.encrypt(SECRET)

# Send `encrypted_key` to the downstream server to process

Methods

This section will go through the following story (if you look at the code snippets) and invoke each of the methods in the API along the way:

  1. Account A is created and airdropped 10 SOL
  2. A creates an NFT N
  3. Account B is created
  4. A pays B's rent fee
  5. N is minted to B associated token account
  6. Account C is created
  7. A pays C's rent fee
  8. B transfers N to C
  9. C destroys N

Let's get started:

$ python3 -i -m api.metaplex_api
>>> 

deploy

deploy will create a new NFT token by

  1. Creating a new account from a randomly generated address (invokes CreateAccount from the System Program)
  2. Invoking InitializeMint on the new account
  3. Initializing the metadata for this account by invoking the CreateMetatdata instruction from the Metaplex protocol

Args:

api_endpoint: (str) The RPC endpoint to connect the network. (devnet, mainnet)

name: (str) Name of the NFT Contract (32 bytes max)

symbol: (str) Symbol of the NFT Contract (10 bytes max)

skip_confirmation=True: A flag that tells you to wait for the transaction to be confirmed if set to False (only used for testing, because it requires synchronized/sequential calls)

Example:

>>> account = KeyPair()
>>> cfg = {"PRIVATE_KEY": base58.b58encode(account.seed).decode("ascii"), "PUBLIC_KEY": str(account.public_key), "DECRYPTION_KEY": Fernet.generate_key().decode("ascii")}
>>> api_endpoint = "https://api.devnet.solana.com/"
>>> Client(api_endpoint).request_airdrop(account.public_key, int(1e10))
{'jsonrpc': '2.0', 'result': '4ojKmAAesmKtqJkNLRtEjdgg4CkmowuTAjRSpp3K36UvQQvEXwhirV85E8cvWYAD42c3UyFdCtzydMgWokH2mbM', 'id': 1}
>>> metaplex_api = MetaplexAPI(cfg)
>>> seller_basis_fees = 0 # value in 10000 
>>> metaplex_api.deploy(api_endpoint, "A"*32, "A"*10, seller_basis_fees)
'{"status": 200, "contract": "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "msg": "Successfully created mint 7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "tx": "2qmiWoVi2PNeAjppe2cNbY32zZCJLXMYgdS1zRVFiKJUHE41T5b1WfaZtR2QdFJUXadrqrjbkpwRN5aG2J3KQrQx"}'
>>> 

Note that when sending SOL to the newly generated account, that account will serve as the fee payer. You can check out this transaction on the Solana Block Exporer.

wallet

wallet creates a new random public/private keypair

>>> metaplex_api.wallet()
'{"address": "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "private_key": [95, 46, 174, 145, 248, 101, 108, 111, 128, 44, 41, 212, 118, 145, 42, 242, 84, 6, 31, 115, 18, 126, 47, 230, 103, 202, 46, 7, 194, 149, 42, 213]}'
>>>

No network calls are made here

topup

topup sends a small amount of SOL to the destination account by invoking Transfer from the System Program

Args:

api_endpoint: (str) The RPC endpoint to connect the network. (devnet, mainnet)

to: (str) The base58 encoded public key of the destination address

amount: (Union[int, None]) This is the number of lamports to send to the destination address. If None (default), then the minimum rent exemption balance is transferred.

>>> metaplex_api.topup(api_endpoint, "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh")
'{"status": 200, "msg": "Successfully sent 0.00203928 SOL to VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "tx": "32Dk647Fb6aKJyErVfxgtSfC4xbssoJprcB7BEmEAdYTFK96M5VEQ1z62QxCCC7tAPF1g9TNvMehoGNudLNaKTWE"}'
>>> 

tx link

mint

mint will mint a token to a designated user account by

  1. Fetching or creating an AssociatedTokenAccount from a Program Derived Address
  2. Invoking MintTo with the AssociatedTokenAccount as the destination
  3. Invoking the UpdateMetadata instruction from the Metaplex protocol to update the uri of the contract (containing the actual content)

Args:

api_endpoint: (str) The RPC endpoint to connect the network. (devnet, mainnet)

contract_key: (str) The base58 encoded public key of the mint address

dest_key: (str) The base58 encoded public key of the destinaion address (where the contract will be minted)

link: (str) The link to the content of the the NFT

>>> metaplex_api.mint(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "https://arweave.net/1eH7bZS-6HZH4YOc8T_tGp2Rq25dlhclXJkoa6U55mM/")
'{"status": 200, "msg": "Successfully minted 1 token to DkrGGuqn183rNyYHQNo9NSDYKZB8FVsaPBGn3F6nG7iH", "tx": "5r4qY1LudNg49FXyduadoAm83cJDWVeypUX6dsGs91RJqSxzU5qTt9WXfXs3Lzs5ZGQsTDTRpDyiXorv1wCzrzsJ"}'
>>> 

tx link

send

send will send a token from one user account to another user account

  1. Fetching the AssociatedTokenAccount from a Program Derived Address for the sender
  2. Fetching or creatign the AssociatedTokenAccount from a Program Derived Address for the receiver
  3. Invoking Transfer (from the Token Program) with the receiver's AssociatedTokenAccount as the destination

Args:

api_endpoint: (str) The RPC endpoint to connect the network. (devnet, mainnet)

contract_key: (str) The base58 encoded public key of the mint address\

sender_key: (str) The base58 encoded public key of the source address (from which the contract will be transferred)

dest_key: (str) The base58 encoded public key of the destinaion address (to where the contract will be transferred)

encrypted_private_key: (bytes) The encrypted private key of the sender

>>> metaplex_api.wallet()
'{"address": "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", "private_key": [172, 155, 209, 75, 226, 68, 91, 22, 199, 75, 148, 197, 143, 10, 211, 67, 5, 160, 101, 15, 139, 33, 208, 65, 59, 198, 5, 41, 167, 206, 85, 83]}'
>>> metaplex_api.topup(api_endpoint, "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8")
'{"status": 200, "msg": "Successfully sent 0.00203928 SOL to EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", "tx": "4erc1aPC8fSNV1kb41mgUSgMKMHhd8FdDd4gqFPQ9TmmS48QcaAi9zpNjzMG3UNr1dDw1mBxThZCgJyUPchiV3Jz"}'
>>> encrypted_key = metaplex_api.cipher.encrypt(bytes([95, 46, 174, 145, 248, 101, 108, 111, 128, 44, 41, 212, 118, 145, 42, 242, 84, 6, 31, 115, 18, 126, 47, 230, 103, 202, 46, 7, 194, 149, 42, 213]))
>>> metaplex_api.send(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", encrypted_key)
'{"status": 200, "msg": "Successfully transfered token from VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh to EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", "tx": "3ZsGcCfjUXviToSB4U6Wg1W1W4rm8bMT7wF8zfauTciK6PdszpLqcvmmYqqrz8mRGK8pQPABVewCk8EdsvNVhzp6"}'

tx link

burn

burn will remove a token from the blockchain

  1. Fetching the AssociatedTokenAccount from a Program Derived Address for the owner
  2. Invoking Burn (from the Token Program) with the owner's AssociatedTokenAccount as the destination

Args:

api_endpoint: (str) The RPC endpoint to connect the network. (devnet: https://api.devnet.solana.com/, mainnet: https://api.mainnet-beta.solana.com/)

contract_key: (str) The base58 encoded public key of the mint address

owner_key: (str) The base58 encoded public key of the owner address

encrypted_private_key: (bytes) The encrypted private key of the owner

>>> encrypted_key = metaplex_api.cipher.encrypt(bytes([172, 155, 209, 75, 226, 68, 91, 22, 199, 75, 148, 197, 143, 10, 211, 67, 5, 160, 101, 15, 139, 33, 208, 65, 59, 198, 5, 41, 167, 206, 85, 83]))
>>> metaplex_api.burn(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", encrypted_key)
'{"status": 200, "msg": "Successfully burned token 7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG on EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", "tx": "5kd5g4mNBSjoTVYwAasWZx6iB8ijaELfBukKrNYBeDvLomK7iTqFH1R29yniEGcfajakDxsqmYCDgDvukihRyZeZ"}'
>>> 

https://explorer.solana.com/tx/5kd5g4mNBSjoTVYwAasWZx6iB8ijaELfBukKrNYBeDvLomK7iTqFH1R29yniEGcfajakDxsqmYCDgDvukihRyZeZ?cluster=devnet

Full Example Code:

This is the sequential code from the previous section. These accounts will need to change if you want to do your own test.

account = KeyPair()
cfg = {"PRIVATE_KEY": base58.b58encode(account.seed).decode("ascii"), "PUBLIC_KEY": str(account.public_key), "DECRYPTION_KEY": Fernet.generate_key().decode("ascii")}
api_endpoint = "https://api.devnet.solana.com/"
Client(api_endpoint).request_airdrop(account.public_key, int(1e10))

# Create API
metaplex_api = MetaplexAPI(cfg)

# Deploy
metaplex_api.deploy(api_endpoint, "A"*32, "A"*10, 0)

# Topup VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh
metaplex_api.topup(api_endpoint, "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh")

# Mint
metaplex_api.mint(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "https://arweave.net/1eH7bZS-6HZH4YOc8T_tGp2Rq25dlhclXJkoa6U55mM/")

# Topup EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8
metaplex_api.topup(api_endpoint, "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8")

# Send
encrypted_key = metaplex_api.cipher.encrypt(bytes([95, 46, 174, 145, 248, 101, 108, 111, 128, 44, 41, 212, 118, 145, 42, 242, 84, 6, 31, 115, 18, 126, 47, 230, 103, 202, 46, 7, 194, 149, 42, 213]))
metaplex_api.send(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", encrypted_key)

# Burn
encrypted_key = metaplex_api.cipher.encrypt(bytes([172, 155, 209, 75, 226, 68, 91, 22, 199, 75, 148, 197, 143, 10, 211, 67, 5, 160, 101, 15, 139, 33, 208, 65, 59, 198, 5, 41, 167, 206, 85, 83]))
metaplex_api.burn(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "EnMb6ZntX43PFeX2NLcV4dtLhqsxF9hUr3tgF1Cwpwu8", encrypted_key)
 

python-api's People

Contributors

aradica avatar crypt0miester avatar halaprix avatar jarry-xiao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-api's Issues

Deploy not working

It appears the deploy function is no longer working as the test_api.py is failing and returning a 400 status response on deploy calls. anyone have a fix to this or as to why it might be happening?

Readme tutorial erroring out at mint step

I'm getting this error at this line

metaplex_api.mint(api_endpoint, "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh", "https://arweave.net/1eH7bZS-6HZH4YOc8T_tGp2Rq25dlhclXJkoa6U55mM/")
File "/Users/metaplex-foundation/python-api/metaplex/metadata.py", line 182, in get_metadata
data = base64.b64decode(client.get_account_info(metadata_account)['result']['value']['data'][0])
TypeError: 'NoneType' object is not subscriptable

and stepping through the error it's crashing because there value is None
-> data = base64.b64decode(client.get_account_info(metadata_account)['result']['value']['data'][0])
(Pdb) client.get_account_info(metadata_account)
{'jsonrpc': '2.0', 'result': {'context': {'slot': 83349421}, 'value': None}, 'id': 2}

missing an argument when calling to function

data=create_metadata_instruction_data(name, symbol, [str(source_account.public_key())]) line 64 in transactions.py this function takes 4 argument but fee is not given as you can see in def create_metadata_instruction_data(name, symbol, fee, creators): on line 91 metadata.py

Cannot see transactions on devnet.solana.com

After running some of the code and receiving what looks like a successful response, looking up the transaction hash on devnet doesn't come up with anything.

{'jsonrpc': '2.0', 'result': '266m3pYNbEifjCAoTMcr4WCgbZSjd4wqtnQ5e2u35JL6dD9MWXESo34bpVEyCNxAk7J8PeG6b3pRHC2wAp7Jnvwz', 'id': 1}
>>> metaplex_api = MetaplexAPI(cfg)
>>> metaplex_api.deploy(api_endpoint, "A"*32, "A"*10)
cedEnGMpDiU38DmPokBxHFQnEm84UAPej2ZTLe1dTLe
{'jsonrpc': '2.0', 'result': '35EgjriuQFMVwejgo9jvDCx8veEgd3hPPVEmZe4V2L7aLh4re7nUqpKPQq8fLEguaffwqcAeAiwxLH7mGyoyNZoH', 'id': 2}
metaplex_api.topup(api_endpoint, "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh")
kk'{"jsonrpc": "2.0", "result": "35EgjriuQFMVwejgo9jvDCx8veEgd3hPPVEmZe4V2L7aLh4re7nUqpKPQq8fLEguaffwqcAeAiwxLH7mGyoyNZoH", "id": 2, "contract": "cedEnGMpDiU38DmPokBxHFQnEm84UAPej2ZTLe1dTLe", "status": 200}'
>>> metaplex_api.topup(api_endpoint, "VtdBygLSt1EJF5M3nUk5CRxuNNTyZFUsKJ4yUVcC6hh")
{'jsonrpc': '2.0', 'result': '4WMYh6k2v3a8qw49MDG2fNRkW6D9CuGNv7KDvxSd2r2sRuEJLBpbToEbHpFYcdJsFoyxLsQB9ADC1Pfn1FvsNA8j', 'id': 2}
'{"jsonrpc": "2.0", "result": "4WMYh6k2v3a8qw49MDG2fNRkW6D9CuGNv7KDvxSd2r2sRuEJLBpbToEbHpFYcdJsFoyxLsQB9ADC1Pfn1FvsNA8j", "id": 2, "status": 200}'```

deploy generating generic account, not a token mint

running metaplex_api.deploy(api_endpoint, "<name>", "<symbol>", seller_basis_fees) I should expect a token account to be created however it ends up creating a generic account.
'{"jsonrpc": "2.0", "result": "3Z9ez2QjnjgL14haPSXHkeHviYKxomC9m3hb4SmgoUZM6kQfTGYvogK7Bai5uxREEwq1d8VMKpHWbtBBUk7oRFif", "id": 2, "contract": "AMtrrdq3z36vKiUY2a6FxJ6zytgrQDQKBqB59G3zpMX5", "status": 200}'
explorer https://explorer.solana.com/address/AMtrrdq3z36vKiUY2a6FxJ6zytgrQDQKBqB59G3zpMX5?cluster=devnet

In the docs the json response is '{"status": 200, "contract": "7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "msg": "Successfully created mint 7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG", "tx": "2qmiWoVi2PNeAjppe2cNbY32zZCJLXMYgdS1zRVFiKJUHE41T5b1WfaZtR2QdFJUXadrqrjbkpwRN5aG2J3KQrQx"}' with "Successfully created mint"... and explorer shows the contact as an unknown token. https://explorer.solana.com/address/7bxe7t1aGdum8o97bkuFeeBTcbARaBn9Gbv5sBd9DZPG/metadata?cluster=devnet

Any attempts to mint produce error:
TypeError: 'NoneType' object is not subscriptable

Intermittent 'code': -32002

Getting intermitten {'code': -32002, 'message': 'Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.', 'data': {'accounts': None, 'err': 'AccountNotFound', 'logs': []}}

What is the cause of this?

Cheers,
Justin

incorrect requirement for python version on project readme

pip install -r requirements.txt exits with error:
ERROR: Could not find a version that satisfies the requirement solana==0.19.1 (from versions: 0.0.3, 0.0.4)

starting from 0.0.5, solana pip package requires python version >=3.7
README file states that python 3.6 is enough

Outdated function

As provided here, the solana.account funcion is deprecated.
Due this deprecated error, metaplex_api.deploy(api_endpoint, "MintNome"*32, "MintSimbolo"*10) returns a Failed attempt 0: ('invalid public key input:', '<solana.account.Account object at 0x0000022E3F77C310>')

Test net endpoint not working.

When using any test net endpoint the process of deploying a contract does not work:

These are some of my logs:
I added:

def await_confirmation(client, signatures, max_timeout=60, target=20, finalized=True):
    elapsed = 0
    while elapsed < max_timeout:
        sleep_time = 5
        time.sleep(sleep_time)
        elapsed += sleep_time
        resp = client.get_signature_statuses(signatures)
        log.debug(resp)
        ...
INFO     uvicorn:metadata.py:135 Metadata account 8jTFMZm1ZnNtMUZhA447kxUGyjkro3Gyq5teDBiSkRwY
INFO     uvicorn:metaplex_api.py:53 Contract H3GhaJf18aYgmxWxtCz6RTuJ4uUqVteUqB3RLUxJeYdP
INFO     uvicorn:execution_engine.py:14 {'jsonrpc': '2.0', 'result': '2TTfGUDbh6S1Tj7pZdPUQU3UfG2bf9vizerjCCcgJjr2LzpJcszjzFLzS9dqfrhHDVVMiZ26gwDk5NE7kKdjbSvP', 'id': 2}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912377}, 'value': [None, None]}, 'id': 3}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912390}, 'value': [None, None]}, 'id': 4}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912399}, 'value': [None, None]}, 'id': 5}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912414}, 'value': [None, None]}, 'id': 6}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912427}, 'value': [None, None]}, 'id': 7}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912439}, 'value': [None, None]}, 'id': 8}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912452}, 'value': [None, None]}, 'id': 9}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912464}, 'value': [None, None]}, 'id': 10}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912477}, 'value': [None, None]}, 'id': 11}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912484}, 'value': [None, None]}, 'id': 12}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912484}, 'value': [None, None]}, 'id': 13}
DEBUG    uvicorn:execution_engine.py:31 {'jsonrpc': '2.0', 'result': {'context': {'slot': 120912484}, 'value': [None, None]}, 'id': 14}

Outdated create metadata instruction

Problem:
The Metaplex Python API experiences a deployment issue where an outdated instruction, specifically the create_metadata_instruction within the transaction.py file, leads to a contract key with value = None during Solana smart contract deployment.

Details:

File: transaction.py
Specific Issue: create_metadata_instruction sends outdated instructions to the Token Metadata Program.
Steps to Reproduce:

Deploy a Solana smart contract with the Metaplex Python API.
Observe that the outdated instruction results in a contract key without a value.
Expected Behavior:
The Metaplex Python API should send current instructions to the Token Metadata Program to ensure successful contract deployment.

None type error when trying to api.mint

Traceback (most recent call last):
File "/Users/xxx/PycharmProjects/Solana/test/test_api.py", line 95, in
test()
File "/Users/xxx/PycharmProjects/Solana/test/test_api.py", line 68, in test
mint_to_response = api.mint(api_endpoint, "xxx", "xxx", "https://testing.com")
File "/Users/xxx/PycharmProjects/Solana/api/metaplex_api.py", line 77, in mint
tx, signers = mint(api_endpoint, self.account, contract_key, dest_key, link, supply=supply)
File "/Users/xxx/PycharmProjects/Solana/metaplex/transactions.py", line 164, in mint
metadata = get_metadata(client, mint_account)
File "/Users/xxx/PycharmProjects/Solana/metaplex/metadata.py", line 180, in get_metadata
data = base64.b64decode(client.get_account_info(metadata_account)['result']['value']['data'][0])
TypeError: 'NoneType' object is not subscriptable

When I did some digging infact its true based on the value is none your looking for in the line - what are you looking for here? The JSON is providing a null field.

print(client.get_account_info("D3EjGmwj33jVS5ZqYPr4njJMVBGR682rwYCTRAKswD1p"))
{'jsonrpc': '2.0', 'result': {'context': {'slot': 93025204}, 'value': {'data': ['', 'base64'], 'executable': False, 'lamports': 1000000000, 'owner': '11111111111111111111111111111111', 'rentEpoch': 227}}, 'id': 1}

print(client.get_account_info("

")['result']['value']['data'][0])
''

Failing on Pycharm

Traceback (most recent call last):
File "/Users/xxx/PycharmProjects/Solana/test/test_api.py", line 11, in
from api.metaplex_api import MetaplexAPI
File "/Users/xxx/PycharmProjects/Solana/api.py", line 1, in
from api.metaplex_api import MetaplexAPI
ModuleNotFoundError: No module named 'api.metaplex_api'; 'api' is not a package

Error with miting

Hi community,

So I'm trying to mint an NFT on Solana using your library but I'm getting an error at metada function. Here the stuck

File "/python-api/api/metaplex_api.py", line 77, in mint
tx, signers = mint(api_endpoint, self.keypair, contract_key, dest_key, link, supply=supply)
File "/python-api/metaplex/transactions.py", line 186, in mint
metadata = get_metadata(client, mint_account)
File "/python-api/metaplex/metadata.py", line 182, in get_metadata
data = base64.b64decode(client.get_account_info(metadata_account)['result']['value']['data'][0])
TypeError: 'NoneType' object is not subscriptable

also how I know the fee on the network to mint the NFT? I check the library, there is no such function as such. It would be great to add it before deciding to mint the contract as such.

Your help will be really appreciated.

Max retries exceeded (api.mint...)

Hello,

I'm getting this error and my transactions not finished properly but charged :)
Do you have any idea for this error please?

Failed attempt 0: HTTPSConnectionPool(host='api.mainnet-beta.solana.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10fcc3ac0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

When I deploy, sometimes I succeed and sometimes I fail. Who can help solve this problem,That's strange!!

def get_metadata(client, mint_key):
    metadata_account = get_metadata_account(mint_key)
    client_metadata_account = client.get_account_info(metadata_account)
    print(client_metadata_account)
    data = base64.b64decode(client_metadata_account['result']['value']['data'][0])
    # data = base64.b64decode(client.get_account_info(metadata_account)['result']['value']['data'][0])
    metadata = unpack_metadata_account(data)
    return metadata

Output 

{'jsonrpc': '2.0', 'result': {'context': {'slot': 109953095}, 'value': None}, 'id': 2}

some time can get value some time value is None
plz help me ~~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.