Getting strange return value from web3.eth.sendTransaction function which can't be used from .getTransactionReceipt
Script works with ganache-cli.
Python
import json
import web3
import time
from web3 import Web3, HTTPProvider, TestRPCProvider
def setup_Web3():
global web3
web3 = Web3(HTTPProvider('http://localhost:8545'))
print("sucessfully set up Web3 Env to Account: ", w3.eth.accounts[0])
is_unlocked = w3.personal.unlockAccount(w3.eth.accounts[0], "TestTestTest", 15000)
print("Sucessfully unlocked? {}".format(is_unlocked))
#[...]
contract = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
contract_data = contract.constructor().buildTransaction(transaction={'from': w3.eth.accounts[0], 'gasPrice': 20000})
deploy_txn = web3.eth.sendTransaction(contract_data)
print (deploy_txn)
tx_receipt = w3.eth.getTransactionReceipt(deploy_txn)
print (tx_receipt)
contract_address = tx_receipt['contractAddress']
Output
b'm\xb6\xc3R?\xcb\xf2\x7fP2QG\xac\x11\xb2mH\xe3\x8c\xba\xcc\r\x14%\xa7\xc0\xd0\x999\x88\x03\xa6'
None
Traceback (most recent call last):
File "deploy.py", line 68, in <module>
contract_address = deploy_contract(contract_interface)
File "deploy.py", line 47, in deploy_contract
contract_address = tx_receipt['contractAddress']
TypeError: 'NoneType' object is not subscriptable
Geth CLI-Call
geth --datadir /home/user/geth-testnetwork/ --networkid 27 --rpc --rpcapi="db,eth,net,web3,personal,web3" --mine --minerthreads=1 console
ABI
{"abi": [{"name": "permissions", "inputs": [{"name": "", "type": "address"}], "type": "function", "outputs": [{"name": "write", "type": "uint256"}, {"name": "read", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "lastCompletedMmigration", "inputs": [], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestSignature", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "bytes"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestJti", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestExp", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestIss", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "address"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestSub", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "addPermissionRequest", "inputs": [], "type": "function", "outputs": [], "stateMutability": "nonpayable", "constant": false, "payable": false}, {"name": "addPermissionRequest", "inputs": [{"name": "_permissionId", "type": "bytes32"}, {"name": "_alg", "type": "bytes32"}, {"name": "_typ", "type": "bytes32"}, {"name": "_iss", "type": "address"}, {"name": "_sub", "type": "uint256"}, {"name": "_audience", "type": "uint256"}, {"name": "_exp", "type": "uint256"}, {"name": "_nbf", "type": "uint256"}, {"name": "_iat", "type": "uint256"}], "type": "function", "outputs": [], "stateMutability": "nonpayable", "constant": false, "payable": false}, {"name": "permissionList", "inputs": [{"name": "", "type": "bytes32"}], "type": "function", "outputs": [{"name": "alg", "type": "bytes32"}, {"name": "typ", "type": "bytes32"}, {"name": "iss", "type": "address"}, {"name": "sub", "type": "uint256"}, {"name": "audience", "type": "uint256"}, {"name": "exp", "type": "uint256"}, {"name": "nbf", "type": "uint256"}, {"name": "iat", "type": "uint256"}, {"name": "jti", "type": "uint256"}, {"name": "signature", "type": "bytes"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "owner", "inputs": [], "type": "function", "outputs": [{"name": "", "type": "address"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestAud", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestTyp", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "bytes32"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestAlg", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "bytes32"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestIat", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"name": "getRequestNbf", "inputs": [{"name": "_permissionId", "type": "bytes32"}], "type": "function", "outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view", "constant": true, "payable": false}, {"inputs": [], "type": "constructor", "stateMutability": "nonpayable", "payable": false}, {"name": "PermissionRequestdeployed", "inputs": [{"name": "permissionId", "type": "bytes32", "indexed": false}], "type": "event", "anonymous": false}, {"name": "PermissionGranted", "inputs": [{"name": "permissionId", "type": "bytes32", "indexed": false}], "type": "event", "anonymous": false}], "devdoc": "{\"methods\":{}}"}
getTransactionReceipt returns None when the transaction has not yet been mined. You will need to implement some form of waiting for the receipt. You can make use of web3.eth.waitForTransactionReceipt if you're using a new enough web3 (which it appears you are)
Most helpful comment
getTransactionReceiptreturnsNonewhen the transaction has not yet been mined. You will need to implement some form of waiting for the receipt. You can make use ofweb3.eth.waitForTransactionReceiptif you're using a new enough web3 (which it appears you are)