ソフトウェアアプリケーションのNFT(ERC721、ERC1155)トークンの統合と採用を促進するように設計されたPythonパッケージ。
1.2.2A1では、出力クラスが統合されますが、すべての関数が生に戻ります
NFTPYは、RPCを介してEthereum Virtual Machine(EVM)との相互作用を可能にし、契約の詳細とトークンホルダーを取得します。クライアントとブロックチェーンの間の直接的な通信経路を提供します。現在、トランザクション方法はサポートされていませんが、将来の更新に実装されます。次の方法が利用可能です。
NFTPYには、バランスのクエリ、ガソリン価格の取得、NFTの転送など、イーサリアムウォレットと対話するための包括的な機能が含まれています。ウォレットインターフェイスは、読み取り専用操作とトランザクション操作の両方をサポートします。
ウォレット機能:
NFTPYには、APIキーを介してOpenseaと対話するための組み込みインターフェイスが含まれています。これにより、オペンシーへのパッケージ内のクエリが可能になり、価格設定情報やその他のオペンシー固有のデータへのアクセスが可能になります。 OpenSeaインターフェイスは、単一のコレクションに焦点を合わせたり、複数のコレクションをクエリするように構成できます。利用可能な方法には以下が含まれます。
Openseaクラス:
OpenseCollectionクラス:
openseawalletクラス:
NFTPYには、APIキーを介してraribleと相互作用するための包括的なインターフェイスが含まれています。これにより、パッケージ内のクエリが適切になり、NFT情報、市場データなどへのアクセスが可能になります。利用可能な方法には以下が含まれます。
著しいクラス:
NFTPYを使用すると、特定のチェーンID、RPC URL、エクスプローラーURL、および名前を備えたカスタムチェーンを作成できます。この機能は、ライブラリで事前に定義されていないブロックチェーンネットワークを追加できるようにすることにより、柔軟性を向上させます。
カスタムチェーンの作成:
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を使用すると、Ethereum MainnetのPixelmon NFTコレクションを照会します!まず、クラスを作成することから始めます。クラスを3つの議論で定義します。
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トークンの場合、複数のトークンIDの残高を照会し、承認を確認できます。
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'} トランザクションハッシュを取得した後、ブロックチェーンでトランザクションが処理されるまでプログラムを遅らせることができます。
# 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 読み取り専用アドレス(つまり、秘密鍵ではなくアドレスのみを提供する)を使用する場合、ブロックチェーンと対話して情報をクエリすることができますが、トランザクションを実行することはできません。これは、機密資格情報を必要とせずにウォレットを監視し、データを取得するのに役立ちます。
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}まず、次の引数を使用してクラスを作成することから始めます。
注意:チェーンを定義する場合、APIにはチェーン定義に特別な形式が必要なため、 nftpy.OpenSea.OpenSeaChainで実行する必要があります。
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' )特定のアカウントが所有するNFTをリストするには、次の方法を使用します。
opensea . list_nfts_by_account ( '0xYourWalletAddress' )コレクションを管理するには、 OpenseCollectionクラスのインスタンスを作成します。
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 ()まず、次の引数を使用してクラスを作成することから始めます。
注:チェーンを定義する場合、APIにはチェーン定義に特別な形式が必要なため、 nftpy.rarible.rariblechainで実行する必要があります。
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' })Raribleプロトコルのデータをエンコードするには、次の方法を使用します。
rarible . encode_data ( data = { 'your' : 'data' })特定の通貨のUSD為替レートを取得するには、次の方法を使用してください。
rarible . get_usd_rate ( 'currency' )サポートされているすべての通貨を取得するには、次の方法を使用します。
rarible . get_all_currencies ()特定の通貨で特定のユーザーの残高を取得するには、次の方法を使用します。
rarible . get_user_balance ( 'user_address' , 'currency' )