[英]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:我正在尝试检查智能合约是否由特定地址发送交易,但下面提到的一些如何在 Remix IDE 上工作,但在使用 python 部署合约时失败。以下是智能合约:
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: //////////////////////////////////////////////// /////////////////////////////////////////// 下面是 python代码:
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");错误:revert("Error Say") revert("Error Speak");
Try to return tx.Origin and address1 variables to check errors.尝试返回 tx.Origin 和 address1 变量来检查错误。 It works perfectly on my hardhat test environment.它在我的安全帽测试环境中完美运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.