I tried to call solidity smart contract public variable using python web3. But when I called, it didn't work and showed the error: 500 (Internal Server Error).
Code summary is like this:
pragma solidity ^0.8.7;
...
contract TestNFT is ERC721Enumerable, Ownable, Pausable {
...
mapping(uint => bool) public locked;
...
}
fashionItemAddress
and abi
are from at first line of this code and they are working well.
@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)})
the result in console is like this:
0xe0ffc7d34f98803e7744cc587f80df19e93a010a760f7af1253c1405ff2faded 11111111
<web3._utils.datatypes.Contract object at 0x0000024679478A60> 2222222222222
[28/Jun/2022 18:47:53] "POST /api/sendTxHashUndress HTTP/1.1" 500 145
I think the problem is to get fContract
. If not, I am not sure what's wrong.
trying as several times and checking code deeply, I never tried to send param in locked()
function.
I mean I have to send param as token_id
in locked(token_id)
like this.
This works for me and this was solved.