[SOLVED] Get tokenId from an address of a contract

hey there,
i wann get the tokenId of the owned nfts from a user in a contract. I wanna trasnfer the nfts but i am missig the tokenId.

How cna i do so ?

You can use getnftsforcontract function to get this data.
https://docs.moralis.io/moralis-dapp/web3-api/nft-api#getnftsforcontract

i only want to get the token ids of a user in a contract. Not of the whole contract

You can pass both user address and contract address to the getnftsforcontract function.

It will return the NFT tokens owned by user address on the contract address.

how can i use this with the deep index moralis api. That would help a lot

This is an example from docs.

Endpoint is /{address}/nft/{token_address}

curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/0x75e3e9c92162e62000425c98769965a76c2e387a/nft/0x2953399124F0cBB46d2CbACD8A89cF0599974963?chain=polygon&format=decimal' \
  -H 'accept: application/json' \
  -H 'X-API-Key: My-API-KEY'

not working for me. I am trying to get the id of a nft to make a safeTransfer :frowning:

i only got the contract address and my wallet address

Did you get any errors?

The returned result array from the API call will have the token_id data. You need to get tokenId from the result array.

This is what i get

Object { total: 1, page: 0, page_size: 100, cursor: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3aGVyZSI6eyJ0b2tlbl9hZGRyZXNzIjoiMHhiMjc2MTRiYThkNTgzZmFmODE3N2VhY2ExMjM5MTg4ZDYzYjRjNGU4Iiwib3duZXJfb2YiOiIweGU1Y2QxZTM0MWFiNTAxZTNmMDExNWI1MmJlYWM5NDFjYWRjN2RjZTYifSwibGltaXQiOjEwMCwib2Zmc2V0IjowLCJvcmRlciI6W1sidHJhbnNmZXJfaW5kZXgiLCJERVNDIl1dLCJwYWdlIjoxLCJrZXkiOiIxNDgyMjkxNC4yMDkuNDM5LjAiLCJ0b3RhbCI6MSwiaWF0IjoxNjU1OTg1MTM3fQ.D1-ZYObQiZkuPRnSenUdihHMDphHjkIeE6rJfaVE3p4", result: (1) […], status: "SYNCED" }
​
cursor: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3aGVyZSI6eyJ0b2tlbl9hZGRyZXNzIjoiMHhiMjc2MTRiYThkNTgzZmFmODE3N2VhY2ExMjM5MTg4ZDYzYjRjNGU4Iiwib3duZXJfb2YiOiIweGU1Y2QxZTM0MWFiNTAxZTNmMDExNWI1MmJlYWM5NDFjYWRjN2RjZTYifSwibGltaXQiOjEwMCwib2Zmc2V0IjowLCJvcmRlciI6W1sidHJhbnNmZXJfaW5kZXgiLCJERVNDIl1dLCJwYWdlIjoxLCJrZXkiOiIxNDgyMjkxNC4yMDkuNDM5LjAiLCJ0b3RhbCI6MSwiaWF0IjoxNjU1OTg1MTM3fQ.D1-ZYObQiZkuPRnSenUdihHMDphHjkIeE6rJfaVE3p4"
​
page: 0
​
page_size: 100
​
result: Array [ {…} ]
​
status: "SYNCED"
​
total: 1
​
<prototype>: Object { … }
main.js:269:17

Did you check the result array data?

1 Like

oh right. Havent opened it. My bad. Yeah its there awesome