소프트웨어 응용 프로그램에서 NFT (ERC721, ERC1155) 토큰의 통합 및 채택을 용이하게하도록 설계된 파이썬 패키지.
1.2.2A1에서는 출력 클래스가 통합되지만 모든 기능은 REAW를 반환합니다.
NFTPY는 RPC를 통해 ETEERIM 가상 머신 (EVM)과의 상호 작용을 가능하게하여 계약 세부 정보 및 토큰 보유자를 검색합니다. 클라이언트와 블록 체인 사이의 직접적인 통신 경로를 제공합니다. 현재 트랜잭션 방법은 지원되지 않지만 향후 업데이트에서 구현 될 것입니다. 다음 방법을 사용할 수 있습니다.
NFTPY에는 잔액 쿼리, 가스 가격 가져 오기 및 NFT 양도를 포함한 이더 리움 지갑과의 상호 작용을위한 포괄적 인 기능이 포함되어 있습니다. 지갑 인터페이스는 읽기 전용 및 트랜잭션 작업을 모두 지원합니다.
지갑 기능 :
NFTPY에는 API 키를 통해 OpenSea와 상호 작용하기위한 내장 인터페이스가 포함되어 있습니다. 이를 통해 포장 쿼리가 OpenSea에 대한 가격 정보 및 기타 OpenSea 별 데이터에 액세스 할 수 있습니다. OpenSea 인터페이스는 단일 컬렉션에 초점을 맞추거나 여러 컬렉션에 중점을 두도록 구성 할 수 있습니다. 사용 가능한 방법에는 다음이 포함됩니다.
Opensea 클래스 :
OpenSeacollection 클래스 :
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 컬렉션을 쿼리 할 것입니다! 우리는 먼저 수업을 만들어 시작할 것입니다. 우리는 세 가지 주장으로 수업을 정의 할 것입니다.
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' )컬렉션을 관리하려면 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 ()우리는 먼저 다음과 같은 주장으로 수업을 만들어 시작합니다.
참고 : 체인을 정의 할 때는 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 . encode_data ( data = { 'your' : 'data' })특정 통화에 대한 USD 환율을 얻으려면 다음 방법을 사용하십시오.
rarible . get_usd_rate ( 'currency' )지원되는 모든 통화를 가져 오려면 다음 방법을 사용하십시오.
rarible . get_all_currencies ()지정된 통화로 특정 사용자의 잔액을 검색하려면 다음 방법을 사용하십시오.
rarible . get_user_balance ( 'user_address' , 'currency' )