def contract_set_via_web3(contract, arg, hashes=None, privateFor=PRIVATE_FOR, gas=GAS_FOR_SET_CALL): """ call the .set(arg) method, possibly with 'privateFor' tx-property using the web3 method """ txParameters = {'from': w3.eth.defaultAccount, 'gas': gas} if privateFor: txParameters['privateFor'] = privateFor # untested # pprint (txParameters) if PARITY_UNLOCK_EACH_TRANSACTION: unlockAccount() tx = contract.functions.insertTransaction('exemplo', 'url', arg).transact(txParameters) # print ("[sent via web3]", end=" ") # TODO: not print this here but at start print(".", end=" ") # TODO: not print this here but at start tx = w3.toHex(tx) if not hashes == None: hashes.append(tx) return tx
def trySmartContractMethods(myContract, gasForSetCall=90000): """ just a test if the contract's methods are working --> call getter then setter then getter """ # get answer1 = myContract.functions.get().call() print('.get(): {}'.format(answer1)) # set if PARITY_UNLOCK_EACH_TRANSACTION: print("unlockAccount:", unlockAccount()) print('.set()') txParameters = {'from': w3.eth.defaultAccount, 'gas': gasForSetCall} tx = myContract.functions.set(answer1 + 1).transact(txParameters) tx_hash = w3.toHex(tx) print("transaction", tx_hash, "... ") sys.stdout.flush() tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash) print("... mined. Receipt --> gasUsed={gasUsed}".format(**tx_receipt)) # get answer2 = myContract.functions.get().call() print('.get(): {}'.format(answer2)) return answer1, tx_receipt, answer2
def test_deployContract(): solfile = os.path.join("hammer", FILE_CONTRACT_SOURCE) name, interface = deploy.compileContract(solfile) print ("unlock: ", clienttools.unlockAccount()) address = deploy.deployContract(interface, ifPrint=True) print (address) assertThatAddress(address)
def contract_CompileDeploySave(contract_source_file): """ compile, deploy, save """ contractName, contract_interface = compileContract(contract_source_file) print("unlock: ", unlockAccount()) contractAddress = deployContract(contract_interface) saveToDisk(contractAddress, abi=contract_interface["abi"]) return contractName, contract_interface, contractAddress
def contract_set_via_web3(contract, arg, privateFor=PRIVATE_FOR, gas=90000): """ call the .set(arg) method, possibly with 'privateFor' tx-property using the web3 method """ txParameters = {'from': w3.eth.defaultAccount, 'gas': gas} if privateFor: txParameters['privateFor'] = privateFor # untested # pprint (txParameters) if PARITY_UNLOCK_EACH_TRANSACTION: unlockAccount() tx = contract.functions.set(x=arg).transact(txParameters) print("[sent via web3]", end=" ") # TODO: not print this here but at start tx = w3.toHex(tx) return tx