def apply_transaction(self, chain: MiningChain) -> None: # Instantiate the contract SimpleToken = self.w3.eth.contract( abi=self.contract_interface['abi'], bytecode=self.contract_interface['bin']) # Build transaction to deploy the contract w3_tx1 = SimpleToken.constructor().buildTransaction(W3_TX_DEFAULTS) tx = new_transaction( vm=chain.get_vm(), private_key=FUNDED_ADDRESS_PRIVATE_KEY, from_=FUNDED_ADDRESS, to=CREATE_CONTRACT_ADDRESS, amount=0, gas=FIRST_TX_GAS_LIMIT, data=decode_hex(w3_tx1['data']), ) logging.debug('Applying Transaction {}'.format(tx)) block, receipt, computation = chain.apply_transaction(tx) deployed_contract_address = computation.msg.storage_address assert computation.is_success # Interact with the deployed contract by calling the totalSupply() API simple_token = self.w3.eth.contract( address=Web3.toChecksumAddress( encode_hex(deployed_contract_address)), abi=self.contract_interface['abi'], ) w3_tx2 = simple_token.functions.totalSupply().buildTransaction( W3_TX_DEFAULTS) tx2 = new_transaction( vm=chain.get_vm(), private_key=FUNDED_ADDRESS_PRIVATE_KEY, from_=FUNDED_ADDRESS, to=deployed_contract_address, amount=0, gas=SECOND_TX_GAS_LIMIT, data=decode_hex(w3_tx2['data']), ) block, receipt, computation = chain.apply_transaction(tx2) assert computation.is_success assert to_int(computation.output) == EXPECTED_TOTAL_SUPPLY
def apply_transaction(self, chain: MiningChain) -> None: if self.config.to_address is None: to_address = generate_random_address() else: to_address = self.config.to_address tx = new_transaction( vm=chain.get_vm(), private_key=FUNDED_ADDRESS_PRIVATE_KEY, from_=FUNDED_ADDRESS, to=to_address, amount=100, data=b'' ) logging.debug('Applying Transaction {}'.format(tx)) block, receipt, computation = chain.apply_transaction(tx) logging.debug('Block {}'.format(block)) logging.debug('Receipt {}'.format(receipt)) logging.debug('Computation {}'.format(computation))