Last active
May 8, 2025 12:25
-
-
Save siexp/3778ca1e9037b39bc184d9c455bc4b30 to your computer and use it in GitHub Desktop.
get nft tokenURI with pure shell commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# curl -X POST https://rpc.berachain.com -H "Content-Type: application/json" -d '{ | |
# "jsonrpc": "2.0", | |
# "id": 1, | |
# "method": "eth_call", | |
# "params": [ | |
# { | |
# "to": "<ADDRESS_OF_SMART_CONTRACT>", | |
# "data": "<HEX_ENCODED_CALL_DATA>" | |
# }, | |
# "latest" | |
# ] | |
# }' | |
# e. g. call to `tokenURI` | |
# 'to' https://berascan.com/token/0x9962b1e4eb4a6fcb4e7d67537db8ed8f402c865f | |
# 'data' keccak-256 encoded 'tokenURI(uint256)' | |
curl -X POST https://rpc.berachain.com -H "Content-Type: application/json" -d '{ | |
"jsonrpc": "2.0", | |
"id": 1, | |
"method": "eth_call", | |
"params": [ | |
{ | |
"to": "0x9962b1e4eb4a6fcb4e7d67537db8ed8f402c865f", | |
"data": "0xc87b56dd0000000000000000000000000000000000000000000000000000000000000001" | |
}, | |
"latest" | |
] | |
}' | |
# expected response | |
# { | |
# "id" : 1, | |
# "jsonrpc" : "2.0", | |
# "result" : "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000044697066733a2f2f62616679626569647970656232376c73783275347a33373671686f65356f67756365676c337065623272337a6e637a676f68756d74366a65716f692f3100000000000000000000000000000000000000000000000000000000" | |
# } | |
# decode result | |
echo "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000044697066733a2f2f62616679626569647970656232376c73783275347a33373671686f65356f67756365676c337065623272337a6e637a676f68756d74366a65716f692f3100000000000000000000000000000000000000000000000000000000" | xxd -r -p | sed 's/\x00//g' | |
# expected output | |
# ipfs://bafybeidypeb27lsx2u4z376qhoe5ogucegl3peb2r3znczgohumt6jeqoi/1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment