简体   繁体   中英

Solidity : tx.origin == address1 does not match, even when both address are same

I am trying to check in smartcontract if the transaction sent by a particular address, but some how the below mentioned works on Remix IDE, but fails when contract is deployed using python. following is the smart contract:

pragma solidity ^0.4.24;
contract ethersend {
    address vin;
    address awa;
    address test;
    
    function say(address address1, address address2) public {
        test = tx.origin;
        vin = address1;
        awa = address2;
        if(tx.origin != address1){
        revert("Error Say");
        }
        else
        {
                revert("Hurray Say");
        }
    }
    
        function speak(address address1, address address2) public {
        test = tx.origin;
        vin = address1;
        awa = address2;
        require(tx.origin == address1,"Error Speak");
        revert("Hurray Speak");
        }
    
}

//////////////////////////////////////////////////////////////////////////////////////////////// below is the python code:

def registerStation1():
    print("\n***********************************************************************************************************")
    print("Test registerStation Method of Smart Contract")
    print("***********************************************************************************************************\n")
    # call transactional method
    #function registerStation(address stationAddress, address ownerAddress, string memory pwd, string memory stationDetails, string memory location, string memory availability,uint priceRate, uint rating, uint ratedby)

    ownerAddress =  "0x9E498002E0e6f7b8208941cF17611de82b64Fec1" #MetaMask Third Account
    ownerPrivateKey = ""
    contract_func1 = contract.functions.speak(ownerAddress, "0xf886D7306336007136D87398B1Ceb4AE194949D2")

    try:
        transaction = contract_func1.buildTransaction()
        nonce = w3.eth.getTransactionCount(ownerAddress)
        transaction['nonce'] = nonce
        #print(transaction)
        signed_Transaction = w3.eth.account.signTransaction(transaction, ownerPrivateKey);
        txn_hash = w3.eth.sendRawTransaction(signed_Transaction.rawTransaction);
        print('txn_hash={} waiting for receipt..'.format(txn_hash.hex()))

        tx_receipt = w3.eth.waitForTransactionReceipt(txn_hash, timeout=240)

        greeting_Event = contract.events.errorLog()
        result = greeting_Event.processReceipt(tx_receipt) # Modification
        print(result[0]['args'])
        print("Receipt accepted. gasUsed={gasUsed} blockNumber={blockNumber}". format(**tx_receipt))

    except Exception as err:
        print("Exception Occured: ",err)
        #raise Exception(err)
    print("\n***********************************************************************************************************")
    print("Test registerStation Method End")
    print("***********************************************************************************************************\n")


registerStation1()

Error: revert("Error Say") revert("Error Speak");

Try to return tx.Origin and address1 variables to check errors. It works perfectly on my hardhat test environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM