I have a smart contract that deploys another smart contract and returns the address of the deployed smart contract. The code for the smart contract looks like this-

contract ContractCreator {
    mapping(address=>address) deployedAddress;
    constructor() public {   
    function createNFT(bytes32 _name) public returns(address){
        MyArtSale ob= new MyArtSale( _name, msg.sender);
        return address(ob);
    function fetchNFT () public view returns(address) {
        return deployedAddress[msg.sender];

I want to interact with the createNFT function using web3.py and following is the python program-

truffleFile = json.load(open('./build/contracts/Ballot.json'))
abi = truffleFile['abi']
address = truffleFile['address']
contract= w3.eth.contract(address=address, abi=abi)

#building transaction
construct_txn = contract.functions.createCourse().buildTransaction({
    'from': acct.address,
    'nonce': w3.eth.getTransactionCount(acct.address),
    'gas': 1728712,
    'gasPrice': w3.toWei('50', 'gwei')})

signed = acct.signTransaction(construct_txn)

tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

How can I access the address that is returned by the createNFT address using the python program

1 Answer 1


Transactions do not have return values, only function calls do. You need to emit events in your function and parse them from the transaction receipt section

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.