แพ็คเกจ Python ที่ออกแบบมาเพื่ออำนวยความสะดวกในการรวมและการยอมรับโทเค็น NFT (ERC721, ERC1155) ในแอพพลิเคชั่นซอฟต์แวร์
ใน 1.2.2a1 คลาสเอาต์พุตจะถูกรวมเข้าด้วยกัน แต่ฟังก์ชั่นทั้งหมดกลับมาดิบ
NFTPY ช่วยให้สามารถโต้ตอบกับ Ethereum Virtual Machine (EVM) ผ่าน RPC เพื่อดึงรายละเอียดสัญญาและผู้ถือโทเค็น มันมีเส้นทางการสื่อสารโดยตรงระหว่างลูกค้าและ blockchain ปัจจุบันวิธีการทำธุรกรรมไม่ได้รับการสนับสนุน แต่จะถูกนำไปใช้ในการอัปเดตในอนาคต มีวิธีการต่อไปนี้:
NFTPY รวมถึงคุณสมบัติที่ครอบคลุมสำหรับการโต้ตอบกับกระเป๋าเงิน Ethereum รวมถึงการสืบค้นยอดคงเหลือราคาก๊าซและการโอน NFTs อินเทอร์เฟซกระเป๋าเงินรองรับทั้งการดำเนินการแบบอ่านอย่างเดียวและการทำธุรกรรม
คุณสมบัติของกระเป๋าเงิน:
NFTPY รวมถึงอินเทอร์เฟซในตัวสำหรับการโต้ตอบกับ OpenSea ผ่านคีย์ API สิ่งนี้จะช่วยให้สามารถค้นหาในแพคเกจใน OpenSea ทำให้สามารถเข้าถึงข้อมูลการกำหนดราคาและข้อมูลเฉพาะ OpenSea อื่น ๆ อินเทอร์เฟซ OpenSea สามารถกำหนดค่าให้มุ่งเน้นไปที่คอลเลกชันเดียวหรือคิวรีคอลเลกชันหลายคอลเลกชัน วิธีการที่มีอยู่รวมถึง:
OpenSea Class:
OpenSeacollection Class:
OpenSeawallet Class:
NFTPY รวมถึงอินเทอร์เฟซที่ครอบคลุมสำหรับการโต้ตอบกับ RARIBLE ผ่านคีย์ API สิ่งนี้ช่วยให้การสืบค้นในแพคเกจสามารถหาไม่ได้ทำให้สามารถเข้าถึงข้อมูล NFT ข้อมูลตลาดและอื่น ๆ ได้ วิธีการที่มีอยู่รวมถึง:
ชั้นเรียนที่น่ากลัว:
NFTPY อนุญาตให้สร้างโซ่ที่กำหนดเองด้วยรหัสโซ่เฉพาะ URL RPC URL Explorer และชื่อ คุณลักษณะนี้ช่วยเพิ่มความยืดหยุ่นโดยเปิดใช้งานการเพิ่มเครือข่าย blockchain ที่ไม่ได้กำหนดไว้ล่วงหน้าในไลบรารี
การสร้างห่วงโซ่ที่กำหนดเอง:
from nftpy . EVM import Chain
custom_chain = Chain (
name = "Ethereum" ,
symbol = "ETH" ,
chain_id = 1 ,
rpc_url = "https://eth.llamarpc.com" ,
explorer_url = "https://etherscan.io" ,
testnet = False
)การใช้ nftpy.evm.nft เรากำลังจะสอบถามคอลเลกชัน Pixelmon NFT บน Ethereum Mainnet! ก่อนอื่นเราจะเริ่มต้นด้วยการสร้างชั้นเรียนของเรา เราจะกำหนดชั้นเรียนของเราด้วยสามข้อโต้แย้ง:
import nftpy . EVM as EVM
Pixelmon = EVM . NFT ( "0x32973908FaeE0Bf825A343000fE412ebE56F802A" , abi = EVM . ABI . ERC721 , network = EVM . Chains . ETH )
# Contract Address ABI Network To Query (Ethereum)ตอนนี้เราได้สร้างวัตถุ NFT ของเราแล้วเราสามารถสอบถามได้ เราจะเริ่มต้นด้วยการได้รับข้อมูลเมตาของโทเค็น ฉันแค่ใส่โทเค็นแบบสุ่มเป็นอาร์กิวเมนต์
print ( Pixelmon . get_token_metadata ( 5580 ))หลังจากเรียกใช้สิ่งนี้เราควรเห็นผลลัพธ์ที่คล้ายกัน
{
"name" : " Pixelmon #5580 " ,
"image_url" : " https://pixelmon-training-rewards.s3-accelerate.amazonaws.com/0/Moler.jpg " ,
"external_url" : " https://pixelmon.club/ " ,
"reward_bitmask" : 6 ,
"attributes" : [
{ "trait_type" : " Species " , "value" : " Moler " },
{ "trait_type" : " Origin " , "value" : " Earth " },
{ "trait_type" : " Rarity " , "value" : " Uncommon " },
{ "trait_type" : " Evolution " , "value" : " Evolution 1 " },
{ "trait_type" : " Hatched On " , "display_type" : " date " , "value" : 1672272943 }
],
"animation_url" : " https://pixelmon-training-rewards.s3-accelerate.amazonaws.com/6/Moler.mp4 "
}
เราสามารถทำสิ่งนี้ได้มากขึ้น ตัวอย่างเช่น:
print ( Pixelmon . get_token_uri ( 5580 ))
print ( Pixelmon . get_owner ( 5580 ))
print ( Pixelmon . get_balance ( "0x5AF7875766D1a50d144DF63E581c0764f6573487" ))
print ( Pixelmon . get_approved ( 5580 ))สำหรับโทเค็น ERC1155 คุณสามารถสืบค้นยอดคงเหลือสำหรับรหัสโทเค็นหลายรายการและตรวจสอบการอนุมัติ:
erc1155_nft = EVM . NFT ( contract_address = '0xYourERC1155ContractAddress' , network = EVM . Chains . ETH , abi = EVM . ABI . ERC1155 )
wallet_address = '0xYourWalletAddress'
token_id = 1
token_ids = [ 1 , 2 , 3 , 4 , 5 ]
# Get the balance of a specific token owned by the wallet
token_balance = erc1155_nft . get_token_balance ( wallet_address , token_id )
print ( f'Token ID { token_id } Balance: { token_balance } ' )
# Get the balance of multiple tokens owned by the wallet
tokens_balance = erc1155_nft . get_tokens ( wallet_address , token_ids )
print ( f'Tokens Balance: { tokens_balance } ' )
# Check if an address is approved for all tokens (ERC1155)
is_approved_erc1155 = erc1155_nft . is_approved_for_all_erc1155 ( wallet_address , '0xOperatorAddress' )
print ( f'Is Approved For All (ERC1155): { is_approved_erc1155 } ' ) การสร้างอินสแตนซ์ของ NFTWallet ต้องใช้คีย์ส่วนตัวสำหรับการเข้าถึงแบบเต็มหรือเพียงแค่ที่อยู่สำหรับการเข้าถึงแบบอ่านอย่างเดียว นอกจากนี้คุณยังสามารถระบุโซ่หลายตัวเพื่อเชื่อมต่อกับเครือข่ายที่แตกต่างกันพร้อมกัน
from nftpy import *
# Initialize the wallet with a private key and specify chains
wallet = NFTWallet ( private_key = "0x9015a0eb4c1ceab5f5544ac6e0a75eabb37d7dec26f1dfcb09adb43632330736" , chains = [ Chains . ETH_SEPOLIA ])
# Get the balance of the wallet in Ether
print ( wallet . get_balance ())
# Output: {"Balances": {'Sepolia Testnet': Decimal('0.8341469847291797')}}
# Get the balance of the wallet in Wei
print ( wallet . get_balance_wei ())
# Output: {"Balances": {'Sepolia Testnet': 834146984729179700}}
# Get the current gas price in Wei
print ( wallet . get_gas_price_wei ())
# Output: {'Sepolia Testnet': 20000000000}
# Get the current gas price in Gwei
print ( wallet . get_gas_price_gwei ())
# Output: {'Sepolia Testnet': Decimal('20')}
# Transfer an NFT to another wallet
to_wallet = "0xa693190103733280E23055BE70C838d9b6708b9a"
contract = "0x725Ea5eEA79F1515e34A921b83D4307b325cC8b9"
gas_price = wallet . get_gas_price_gwei ()[ "Sepolia Testnet" ]
gas_limit = 65000 # Disclaimer! Gas Limit set for Sepolia, WILL fail on other networks
# Transfer the NFT and get the transaction hash and explorer URL
print ( wallet . transfer_nft ( to = to_wallet , contract_address = contract , amount = 1 , gas_limit = gas_limit ,
gas_price_gwei = gas_price , abi = ABI . OPENSEA_ERC1155 , token_id = 1 ))
# Output: {'transaction_hash': '0x18a076a4a30c1cc014b1620aa907db06a04e8a709bda47e9beed2233a23f532f', 'explorer_url': 'https://sepolia.etherscan.io/tx/0x18a076a4a30c1cc014b1620aa907db06a04e8a709bda47e9beed2233a23f532f'} หลังจากที่เราได้รับแฮชธุรกรรมเราสามารถล่าช้าโปรแกรมได้จนกว่ากระบวนการทำธุรกรรมใน blockchain
# Wait until the transaction is processed
transaction_hash = "0xcd74c93bbf42cae24f329c45da995bde7e1c89ea848855d04db516c6460eda02"
print ( wallet . wait_until_transaction_processes ( transaction_hash , chain = Chains . ETH_SEPOLIA ))
# Output: True | When the transaction fully processes on the blockchain เมื่อใช้ที่อยู่แบบอ่านอย่างเดียว (เช่นเฉพาะการให้ที่อยู่และไม่ใช่คีย์ส่วนตัว) คุณยังสามารถโต้ตอบกับ blockchain เพื่อสอบถามข้อมูล แต่คุณจะไม่สามารถทำธุรกรรมได้ สิ่งนี้มีประโยชน์สำหรับการตรวจสอบกระเป๋าเงินและการดึงข้อมูลโดยไม่จำเป็นต้องมีข้อมูลประจำตัวที่ละเอียดอ่อน
from nftpy import *
# Initialize the wallet with an address and specify chains
readonly_wallet = NFTWallet ( address = "0xYourReadOnlyWalletAddress" , chains = [ Chains . ETH_SEPOLIA ])
# Get the balance of the wallet in Ether
print ( readonly_wallet . get_balance ())
# Output: {"Balances": {'Sepolia Testnet': Decimal('0.123456789012345678')}}
# Get the balance of the wallet in Wei
print ( readonly_wallet . get_balance_wei ())
# Output: {"Balances": {'Sepolia Testnet': 123456789012345678}}
# Get the current gas price in Wei
print ( readonly_wallet . get_gas_price_wei ())
# Output: {'Sepolia Testnet': 20000000000}ก่อนอื่นเราจะเริ่มต้นด้วยการสร้างชั้นเรียนของเราด้วยอาร์กิวเมนต์ต่อไปนี้:
โปรดทราบ : เมื่อกำหนดห่วงโซ่ควรทำด้วย nftpy.OpenSea.OpenSeaChain เนื่องจาก API ต้องการรูปแบบพิเศษสำหรับนิยามโซ่
from nftpy import OpenSea , OpenSeaChain
opensea = OpenSea ( api_key = 'your-opensea-api-key' , chain = OpenSeaChain . POLYGON )หากต้องการสอบถามสถิติของคอลเลกชัน NFT ให้ใช้วิธีการต่อไปนี้:
opensea . get_collection_stats ( 'your-collection-slug' )หลังจากทำงานแล้วเราควรเห็นผลลัพธ์ที่คล้ายกัน:
{
"stats" : {
"one_day_volume" : 12.34 ,
"one_day_change" : 0.56 ,
"one_day_sales" : 78 ,
"one_day_average_price" : 0.16 ,
"total_volume" : 1234.56 ,
"total_sales" : 7890 ,
"total_supply" : 10000 ,
"count" : 10000 ,
"num_owners" : 2345 ,
"average_price" : 0.123 ,
"num_reports" : 0 ,
"market_cap" : 4567.89 ,
"floor_price" : 0.123
}
}หากต้องการดึงรายละเอียดของคอลเลกชันให้ใช้วิธีการต่อไปนี้:
opensea . get_collection ( 'your-collection-slug' )หากต้องการรับรายละเอียดของ NFT เฉพาะให้ใช้วิธีการต่อไปนี้:
opensea . get_nft ( '0xYourContractAddress' , '1' )หากต้องการแสดงรายการเหตุการณ์ที่เกี่ยวข้องกับ NFT เฉพาะให้ใช้วิธีการต่อไปนี้:
opensea . list_events_by_nft ( '0xYourContractAddress' , '1' )หากต้องการแสดงรายการ NFTs ที่เป็นเจ้าของโดยบัญชีเฉพาะให้ใช้วิธีการต่อไปนี้:
opensea . list_nfts_by_account ( '0xYourWalletAddress' )ในการจัดการคอลเลกชันให้สร้างอินสแตนซ์ของคลาส OpenSeacollection :
from nftpy import OpenSeaCollection
collection = OpenSeaCollection ( collection_name = 'your-collection-name' , api_key = 'your-api-key' )หากต้องการรับรายละเอียดของคอลเลกชันเฉพาะให้ใช้วิธีการต่อไปนี้:
details = collection . get_collection_details ()หากต้องการแสดงรายการ NFT ทั้งหมดภายในคอลเลกชันให้ใช้วิธีการต่อไปนี้:
nfts = collection . get_nfts ()ในการจัดการกระเป๋าเงินให้สร้างอินสแตนซ์ของคลาส OpenSeawallet :
from nftpy import OpenSeaWallet
wallet = OpenSeaWallet ( address = 'your-wallet-address' , api_key = 'your-api-key' )ในการตรวจสอบความสมดุลของกระเป๋าเงินให้ใช้วิธีการต่อไปนี้:
balance = wallet . get_balance ()หากต้องการดึง NFT ทั้งหมดเป็นเจ้าของโดยกระเป๋าเงินให้ใช้วิธีการต่อไปนี้:
nfts = wallet . get_nfts ()ก่อนอื่นเราจะเริ่มต้นด้วยการสร้างชั้นเรียนของเราด้วยอาร์กิวเมนต์ต่อไปนี้:
โปรดทราบ : เมื่อกำหนดห่วงโซ่ควรทำด้วย nftpy.rarible.rariblechain เนื่องจาก API ต้องการรูปแบบพิเศษสำหรับนิยามโซ่
from nftpy import Rarible , RaribleChain
rarible = Rarible ( api_key = 'your-rarible-api-key' , chain = RaribleChain . ETHEREUM )หากต้องการดึงรายละเอียดของรายการเฉพาะด้วย ID ให้ใช้วิธีการต่อไปนี้:
rarible . get_item_by_id ( 'item_id' )หากต้องการดึงรายละเอียดหลายรายการด้วย ID ของพวกเขาใช้วิธีการต่อไปนี้:
rarible . get_items_by_ids ([ 'item_id1' , 'item_id2' ])ในการดึงข้อมูลค่าลิขสิทธิ์สำหรับรายการเฉพาะด้วย ID ให้ใช้วิธีการต่อไปนี้:
rarible . get_item_royalties_by_id ( 'item_id' )ในการดึงรายการที่เป็นเจ้าของโดยที่อยู่เฉพาะให้ใช้วิธีการต่อไปนี้:
rarible . get_items_by_owner ( 'owner_address' )ในการตรวจสอบลายเซ็นสำหรับชุดข้อมูลที่กำหนดให้ใช้วิธีการต่อไปนี้:
rarible . validate_signature ( data = { 'your' : 'data' })ในการรับข้อมูลอินพุตที่จำเป็นสำหรับการสร้างลายเซ็นให้ใช้วิธีการต่อไปนี้:
rarible . get_signature_input ( data = { 'your' : 'data' })ในการเข้ารหัสข้อมูลสำหรับโปรโตคอลที่ RARIBILE ใช้วิธีการต่อไปนี้:
rarible . encode_data ( data = { 'your' : 'data' })ในการรับอัตราแลกเปลี่ยน USD สำหรับสกุลเงินเฉพาะให้ใช้วิธีการต่อไปนี้:
rarible . get_usd_rate ( 'currency' )ในการดึงสกุลเงินที่รองรับทั้งหมดใช้วิธีการต่อไปนี้:
rarible . get_all_currencies ()ในการดึงความสมดุลของผู้ใช้เฉพาะในสกุลเงินที่ระบุให้ใช้วิธีการต่อไปนี้:
rarible . get_user_balance ( 'user_address' , 'currency' )