Open guillaumecote opened 4 years ago
The Contract
classes (and instances) are going to be unpickleable since they are dynamically created classes.
In order to support pickle-ability the Web3
class would need to be pickleable (which I currently would not be surprised if it wasnt). After that we'd need to introduce the pickle APIs for handling custom construction/deconstruction of objects.
This should be a relatively straight forward thing to do for anyone with a little python experience.
Has anyone made progress on this.. I would PAY for this functionality - to be able to store web3 smart contacts in a local mysql db
This hasn't reached the top of our priority queue, so no progress has been made. If you'd like to take a crack at it, @lforet, we'd be happy to review! That's probably the fastest way to get it in at this point.
I stand corrected. What I have done is to abstract one level above the class that contains the method that calls the Contract object and used Pathos multiprocessing instead of the in-built python multiprocessing. It works now.
I need to store w3 contracts in files also for speed up backtesting, please add support to this
pip freeze
output:What was wrong?
I'm trying to find any way to save web3.contracts to limit the amount of calls I generate through infura during code initialization phase.
w3 = Web3(HTTPProvider(infura)) abi = {} with open('uniswap_factory.json') as f: abi['factory'] = json.load(f) contract = w3.eth.contract(address="0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95", abi = abi['factory']) dill.dumps(contract)
AttributeError Traceback (most recent call last) c:\users\sir_s\appdata\local\programs\python\python36-32\lib\pickle.py in _getattribute(obj, name) 268 parent = obj --> 269 obj = getattr(obj, subpath) 270 except AttributeError:
AttributeError: module 'web3._utils.datatypes' has no attribute 'Contract'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last) c:\users\sir_s\appdata\local\programs\python\python36-32\lib\pickle.py in save_global(self, obj, name) 917 module = sys.modules[module_name] --> 918 obj2, parent = _getattribute(module, name) 919 except (ImportError, KeyError, AttributeError):
c:\users\sir_s\appdata\local\programs\python\python36-32\lib\pickle.py in _getattribute(obj, name) 271 raise AttributeError("Can't get attribute {!r} on {!r}" --> 272 .format(name, obj)) 273 return obj, parent
AttributeError: Can't get attribute 'Contract' on <module 'web3._utils.datatypes' from 'C:\Users\Sir_s\AppData\Roaming\Python\Python36\site-packages\web3\_utils\datatypes.py'>
During handling of the above exception, another exception occurred:
PicklingError Traceback (most recent call last)