[英]How to call contract public variable using web3py?
我嘗試使用 python web3 調用solidity 智能合約公共變量。 但是當我打電話時,它不起作用並顯示錯誤:500(內部服務器錯誤)。
代碼摘要是這樣的:
pragma solidity ^0.8.7;
...
contract TestNFT is ERC721Enumerable, Ownable, Pausable {
...
mapping(uint => bool) public locked;
...
}
fashionItemAddress
和abi
來自此代碼的第一行,它們運行良好。
@api_view(['POST'])
def sendTxHashUndress(request):
transaction_hash = request.POST["transaction_hash"]
INFURA_URL = "https://rinkeby.infura.io/v3/9eda0366d20f4627860299a5ac514808"
web3 = Web3(Web3.HTTPProvider(INFURA_URL))
fContract = web3.eth.contract(fashionItemAddress, abi=ABI)
print(fContract, '2222222222222')
print(fContract.call().locked(), '==============')
try:
receiptments = web3.eth.wait_for_transaction_receipt(transaction_hash, 120, 0.1)
print("receiptments", receiptments.status)
if receiptments.status == 1:
return _undressIcongirl(request)
return JsonResponse({'result': 'failed_transaction'})
except Exception as error:
print(str(error))
return JsonResponse({'result': str(error)})
控制台中的結果是這樣的:
0xe0ffc7d34f98803e7744cc587f80df19e93a010a760f7af1253c1405ff2faded 11111111
<web3._utils.datatypes.Contract object at 0x0000024679478A60> 2222222222222
[28/Jun/2022 18:47:53] "POST /api/sendTxHashUndress HTTP/1.1" 500 145
我認為問題在於獲得fContract
。 如果沒有,我不確定出了什么問題。
多次嘗試並深入檢查代碼,我從未嘗試在locked()
函數中發送參數。
我的意思是我必須像這樣在 lock locked(token_id)
中將參數作為token_id
發送。
這對我有用,這已經解決了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.