def console(ipc_path: Path, use_ipython: bool = True, env: Dict[str, Any] = None, banner: str = DEFAULT_BANNER) -> None: """ Method that starts the chain, setups the trinity CLI and register the cleanup function. """ if env is None: env = {} # if ipc_path is not found, raise an exception with a useful message if not ipc_path.exists(): raise FileNotFoundError(create_missing_ipc_error_message(ipc_path)) # wait to import web3, because it's somewhat large, and not usually used import web3 ipc_provider = web3.IPCProvider(ipc_path) w3 = web3.Web3(ipc_provider) # Allow omitting params by defaulting to `None` def rpc(method: RPCEndpoint, params: Dict[str, Any] = None) -> RPCResponse: return ipc_provider.make_request(method, params) namespace = merge({'w3': w3, 'rpc': rpc}, env) shell(use_ipython, namespace, banner)
def console(ipc_path: Path, use_ipython: bool = True, env: Dict[str, Any] = None, banner: str = DEFAULT_BANNER) -> Any: """ Method that starts the chain, setups the trinity CLI and register the cleanup function. """ if env is None: env = {} # if ipc_path is not found, raise an exception with a useful message if not ipc_path.exists(): raise FileNotFoundError(create_missing_ipc_error_message(ipc_path)) # wait to import web3, because it's somewhat large, and not usually used import web3 w3 = web3.Web3(web3.IPCProvider(ipc_path)) namespace = merge({'w3': w3}, env) if use_ipython: ipython_shell(namespace, banner)() else: python_shell(namespace, banner)()
def __init__(self, creator_addr, path_to_metacontract, paths_to_heads, GETH_DATADIR, instrument=True, verbose=True): super().__init__(creator_addr, path_to_metacontract, paths_to_heads, instrument, verbose) self.web3 = web3.Web3(web3.IPCProvider(GETH_DATADIR + '/geth.ipc')) self.web3.personal.unlockAccount(creator_addr, '')
def console(ipc_path, use_ipython=True, env=None, banner=DEFAULT_BANNER): """ Method that starts the chain, setups the trinity CLI and register the cleanup function. """ if env is None: env = {} w3 = web3.Web3(web3.IPCProvider(ipc_path)) namespace = merge({'w3': w3}, env) if use_ipython: shell = ipython_shell(namespace, banner) else: shell = python_shell(namespace, banner) shell()
def console(ipc_path: Path, use_ipython: bool = True, env: Dict[str, Any] = None, banner: str = DEFAULT_BANNER) -> Any: """ Method that starts the chain, setups the trinity CLI and register the cleanup function. """ if env is None: env = {} # cast needed until https://github.com/ethereum/web3.py/issues/867 is fixed w3 = web3.Web3(web3.IPCProvider(str(ipc_path))) namespace = merge({'w3': w3}, env) if use_ipython: ipython_shell(namespace, banner)() else: python_shell(namespace, banner)()
def create_contract(args): with open(args["contract"]) as f: raw_contract = f.read() w3 = web3.Web3(web3.IPCProvider(args["ipc_path"])) if not w3.isConnected(): raise RuntimeError("cound not connect to geth") account = w3.geth.personal.listAccounts()[args["account"]] password = getpass.getpass("Enter account password: "******"from": account, "data": raw_contract, "value": args["value"], }) receipt = w3.eth.waitForTransactionReceipt(result) print( "Contract created at block {blockNumber} with address {contractAddress}" .format(**receipt))
def console(ipc_path: Path, use_ipython: bool = True, env: Dict[str, Any] = None, banner: str = DEFAULT_BANNER) -> Any: """ Method that starts the chain, setups the trinity CLI and register the cleanup function. """ if env is None: env = {} # if ipc_path is not found, raise an exception with a useful message if not ipc_path.exists(): raise FileNotFoundError(create_missing_ipc_error_message(ipc_path)) # cast needed until https://github.com/ethereum/web3.py/issues/867 is fixed w3 = web3.Web3(web3.IPCProvider(str(ipc_path))) namespace = merge({'w3': w3}, env) if use_ipython: ipython_shell(namespace, banner)() else: python_shell(namespace, banner)()
break log.info("Invoking Bytecode Rewriter") constructor_args = b"" assert (len([ x for x in contract_abi if x['type'] == 'constructor' ][0]['inputs']) == 0), "constructor argument currently unsupported!" proxy_constructor = evmpatch.deploy.proxy_deploy(contract_constructor, constructor_args) logic_constructor = evmpatch.deploy.make_deployable(contract_runtime) log.info("Connecting to local Ethereum Node") _ipcpath = "/home/user/.geth.ipc" if os.path.exists('/tmp/geth/geth.ipc'): _ipcpath = '/tmp/geth/geth.ipc' w3 = web3.Web3(web3.IPCProvider(_ipcpath)) # web3py >=5 w3.middleware_onion.inject(web3.middleware.geth_poa_middleware, layer=0) # web3py <5 # w3.middleware_stack.inject(web3.middleware.geth_poa_middleware, layer=0) assert w3.isConnected(), "Web3 API not connected to Ethereum client!" log.info("Connect to Ethereum Node %s", w3.clientVersion) account = w3.eth.accounts[0] log.debug("using account %s", account) w3.eth.defaultAccount = w3.eth.accounts[0] log.info("Deploying Upgradable Contract") proxy_contract = w3.eth.contract( bytecode=proxy_constructor, abi=(contract_abi + evmpatch.proxycontract.PROXY_ABI),
from eth_abi import encode_abi from eth_utils import ( encode_hex, function_abi_to_4byte_selector, ) import web3, time, json from ethereum.tester import languages batch_size = 4 w3 = web3.Web3(web3.IPCProvider('/home/debian/geth_temp_fast/geth.ipc')) timeout = 999999999 # seconds batch_timeout = 1000 wei_per_second = 42738118437506803190 / ( 604800.0 * 2.8) # target wei to consume / (seconds in 1wk) code = '/home/ubuntu/gas/token.sol' pool_addr = '0xTODO' # your address here contract_address = "0x0000000000b3f879cb30fe243b4dfee438691c04" gas_price = int(4e9) + 5 # start gas price (1gwei + epsilon) gas_delta = int(2e9) max_buy = int(25e9) abi = json.loads( '[{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"totalSupply","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"value","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"value","type":"uint256"}],"name":"free","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]' ) tx_gas_consumed = 982614 # Load old batch times # batchtimes is list of (end_nonce,time_start,time_end,wei_consumed) batchtimes = open("batchtimes").read().splitlines() batchtimes = [[int(float(y)) for y in x.split(",")] for x in batchtimes] print "Initial batchtimes loaded, showing last 50"
def newWeb3(): '''Return new IPC-based web3 instance''' return web3.Web3(web3.IPCProvider(GETH_DATADIR + '/geth.ipc'))
def new_web3(): """Return new IPC-based web3 instance""" return web3.Web3(web3.IPCProvider(constants.GETH_DATADIR + '/geth.ipc'))