我正在尝试签入智能契约,如果事务是由特定地址发送的,但是下面提到的一些事务如何在Remix上工作,但是在使用python部署契约时失败。以下是smart合同:
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");
}
}下面的////////////////////////////////////////////////////////////////////////////////////////////////是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()错误:还原(“错误说”)还原(“错误发言”);
发布于 2022-04-07 14:09:01
尝试返回tx.Origin和address1变量以检查错误。它非常适合我的硬质测试环境。
https://stackoverflow.com/questions/71343732
复制相似问题