0

I have a python script that retrieves the NFT asset name, and addresses of a specific policy ID using blockfrost API. Now I need to amend the script to add to the csv whether or not the specific asset is in a smart contract (plutus contract) or not. any ideas?

current script:

import requests,csv

blockfrost_api_key=input('blockfrost api key')
project_policy_id=input('project policy id')

base_api="https://cardano-mainnet.blockfrost.io/api/v0"

headers={'project_id':f'{blockfrost_api_key}'}

allAsset=[]

page=1

while True:
    response=requests.get(f'{base_api}/assets/policy/{project_policy_id}?page={page}',headers=headers)

    if len(response.json())==0:
        break

    for asset in response.json():
        temp={}
        asset_hex_name=asset["asset"][len(project_policy_id):]
        temp['name']=bytearray.decode(bytearray.fromhex(asset_hex_name))
        temp['asset']=asset['asset']

        allAsset.append(temp)
        
    page+=1

data=[]

for asset in allAsset:
    response=requests.get(f'{base_api}/assets/{asset["asset"]}/addresses',headers=headers)
    address=response.json()[0]['address']

    data.append([asset['name'],address])

    print(asset['name'])

file=open('snapshot.csv','w')
csvWriter=csv.writer(file,delimiter=',')
csvWriter.writerows(data)
file.close()

I'm a complete noob and followed a tutorial to get this far. Thanks for any help! greatly appreciated

1 Answer 1

0

You are also there, all you need to do is to fetch the address using the /addresses endpoint and check if the address has a script flag.

2
  • @mmahut how do i do this exactly in my current script? I'm so new to scripting. thanks for any help
    – dpd
    Commented Feb 15, 2023 at 18:00
  • i figured it out with some help from a buddy. thanks
    – dpd
    Commented Feb 18, 2023 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.