python-api
python-api copied to clipboard
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
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]) ''
is that address the mint account public key? in other words the program ID? then you will have data
the data is in this case is metadata of the NFT (the metaplex metadata json schema)
No it is blank if you look at ['result']['value']['data'][0] in the structure its null:
'result': {'context': {'slot': 93025204}, 'value': {'data': ['', 'base64']
Looks like this account has yet to be initialized/populated with data
Where does that get done I dont see that in any of the documentation? I've also queried Dagen Apes on Mainnet - the Update Authority account and its the same blank?
print(client.get_account_info("DC2mkgwhy56w3viNtHDjJQmc7SGu2QX785bS4aexojwX")) {'jsonrpc': '2.0', 'result': {'context': {'slot': 95601447}, 'value': {'data': ['', 'base64'], 'executable': False, 'lamports': 102810501050, 'owner': '11111111111111111111111111111111', 'rentEpoch': 221}}, 'id': 1}
I think the update authority is supposed to be empty. Check the protocol source code. What exactly are you trying to do?
Just trying to use the mint function but it keeps breaking/eroding at that particular point.
Also it would be handy just having a function to update metadata on an existing token -
On Thu, 9 Sep 2021 at 02:17, Jarry Xiao @.***> wrote:
I think the update authority is supposed to be empty. Check the protocol source code. What exactly are you trying to do?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/metaplex-foundation/python-api/issues/8#issuecomment-915684100, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJESKGKEPQD3ZGJ4M3ST53UBADKNANCNFSM5DTMIE6A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are more than welcome to make a PR with the update_metadata fix. I did push some changes a few days ago. Is your branch up to date?
Not sure I've got the skills yet. Yeah its the latest pull I've got.
Can give it a go.. its just the transmission onto the Solana network I need help with.
Did you find any resolution, I am getting same issue
{'jsonrpc': '2.0', 'result': {'context': {'slot': 82578549}, 'value': {'data': ['', 'base64'], 'executable': False, 'lamports': 20000000000, 'owner': '11111111111111111111111111111111', 'rentEpoch': 191}}, 'id': 3}
+1 I'm getting same error too. btw sometimes it is working properly.
data = base64.b64decode(client.get_account_info(metadata_account)['result']['value']['data'][0]) TypeError: 'NoneType' object is not subscriptable
Something is wrong on testnet and devnet, things are working fine on mainnet-beta. This looks to be aproblem at the solana API end where it's not returning the metadata
Same error on devnet, is there anyone who made it work on mainnet?
Faced the same problem today. is this issue because of devnet have some troubles these days?
run the test_api.py, if it works then your code is missing something.
I found the same issue and fixed it by editing metadata.py
.
In the function get_metadata, I added
client_metadata_account = dict(client.get_account_info(metadata_account))
before base64 decoding then it worked (but I don't know why).
The new function will look like:
def get_metadata(client, mint_key):
metadata_account = get_metadata_account(mint_key)
print("Test")
client_metadata_account = dict(client.get_account_info(metadata_account))
data = base64.b64decode(client_metadata_account['result']['value']['data'][0])
metadata = unpack_metadata_account(data)
return metadata
@batprem In my experience it was the raw metadata being returned from the API which was sometimes empty, therefore I think you may have just got lucky when you retried. Just a thought.
@rhamnett It's hards to say but I tried uploading with my modified function and original function by more than 10 times for each. The modified one significantly made all successful attempts whereas the original one made all fail.
In my guess, it would be about asyncio
issue. When API function is first called then the result hold the None
value and wait for a replacement. Then, dict
parsing forces the variable to await
the result and replace None
.
@rhamnett It's hards to say but I tried uploading with my modified function and original function by more than 10 times for each. The modified one significantly made all successful attempts whereas the original one made all fail.
In my guess, it would be about
asyncio
issue. When API function is first called then the result hold theNone
value and wait for a replacement. Then,dict
parsing forces the variable toawait
the result and replaceNone
.
Hello, can you solve this problem? I tried your method and will get some improvement, but sometimes I still make the mistake of agreeing.
I think it might be a timing issue with the deployment of the Program not propagating everywhere by the time the mint is called (on devnet anyway). So for example doing like:
result = api.deploy(api_endpoint, name, symbol, fees)
contract_key = json.loads(result).get('contract')
time.sleep(30)
api.mint(api_endpoint, contract_key, public_key, link_to_json_file)
seems to work 100% of the time for me. Without that sleep, it's super inconsistent (tests included). Also, the 30 seconds there might be overkill I just picked a huge number for testing the theory.
I think a generally good idea for this API is to change the default confirmation status to Confirmed
. When I initially built out this API I wasn't aware of that feature. I think it will make using this a lot more seamless. I currently don't have the cycles to implement this, but I think it would be great if a community member would build out this small change.
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]) ''
make sure that when you deploy it (before even calling the mint), the contract name and contract symbol fields match the name and symbol fields in your metadata json. as soon as I changed this, the mint worked.
@jarry-xiao is their any solution for this issue I am facing the same since many days and cannot find the solution .
@jarry-xiao is their any solution for this issue I am facing the same since many days and cannot find the solution .
see if sleeping for 30 seconds after you deploy then mint would work. this just makes sure that the data has been propagated into the blockchain.
the cleaner way is to "await" for 31 confirmations for the deploy transaction.
@crypt0miester sleeping works sometimes but not all the time we need to be sure that its robust and works .
I also have another question say I want to create say 10 NFT with different metadata do I have to call deploy and mint 10 times or only call deploy 1 and mint 10 times
is this correct
@crypt0miester sleeping works sometimes but not all the time we need to be sure that its robust and works .
I also have another question say I want to create say 10 NFT with different metadata do I have to call deploy and mint 10 times or only call deploy 1 and mint 10 times
example
**for i in range(10):** # alter the json file todayDateString = todays_date.strftime("%m/%d/%Y") _alterJson(todayDateString) # # read the json file and upload to arweave with open('Metadata/metadata.json', 'r') as notjson: Json_data = notjson.read() transaction = Transaction(wallet, data=Json_data) transaction.add_tag('Content-Type', 'application/json') transaction.sign() # Get the trnsaction id for arweave trx_id = transaction.id transaction.send() # create the account **result = json.loads(api.deploy(test_api_endpoint, TOKEN_NAME, TOKEN_SYMBOL, 0))** # check the result status or fail assert result['status'] == 200, "Sorry the account deploy failed" contract_key = result.get('contract') DEPLOYED.append(contract_key) print("current account ",contract_key) # Create actual token **minted = json.loads(api.mint(test_api_endpoint, contract_key, TEST_PUBLIC_KEY, "https://arweave.net/" + trx_id))** MINTED.append(minted) assert minted['status'] == 200, "Sorry the token mint failed" todays_date += timedelta(days=1) print("Finished minting") print("All Accounts : ", DEPLOYED) print("All Minted : ", MINTED)
is this correct
are you on devnet or main?
always be ready for deployment failure. solana might be lagging and transactions might fail.
but each nft has its own contract I believe. so 10 deployments and 10 mints. that's why there is a supply in deploy function.
@crypt0miester thanks i am working on devnet
do you know what @jarry-xiao is talking about to set default status to confirmed for deploy i dont understand how to implement it
@crypt0miester thanks i am working on devnet
do you know what @jarry-xiao is talking about to set default status to confirmed for deploy i dont understand how to implement it
yes.
here is a hint https://github.com/metaplex-foundation/python-api/blob/main/utils/execution_engine.py
I'm on vacation. cant help you more.
@crypt0miester can you tell me {'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': []}} why this error occurred . I have just added the transaction options parameters in send_transaction function like that, result=client.send_transaction(tx,*signers,opts=TxOpts(skip_confirmation=True,skip_preflight=False,preflight_commitment='confirmed')).
@crypt0miester can you tell me {'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': []}} why this error occurred . I have just added the transaction options parameters in send_transaction function like that, result=client.send_transaction(tx,*signers,opts=TxOpts(skip_confirmation=True,skip_preflight=False,preflight_commitment='confirmed')).
check if you have solanas in the wallet address.
secondly change skip_confirmation=False or it will not check if the txn is confirmed or not to begin with. True will just skip the checking.
and please open a new issue.