profile
viewpoint

Ask questionsHandling Promise, Async, and Javascript 'new' objects?

Re: issue 64

I am actually trying to run Ether JS library. The official documentation is available here.

I am trying to create a Wallet using the fromBrainWallet constructor. It takes in an emailID, password and a callback function.

When I use your code, the promise object does not have a property called then.

I have absolutely no idea about how I should handle this.

This is the code I am using (https://docs.ethers.io/ethers.js/html/api-providers.html#connecting-to-ethereum for reference) is able to get a reference to:

let defaultProvider = ethers.getDefaultProvider('ropsten');

but has an error when trying to use a 'new' object re:

let etherscanProvider = new ethers.providers.EtherscanProvider('ropsten');

which is the following:

I/System.out(17764): providerSetupFunction :: function EtherscanProvider(network, apiKey) {
I/System.out(17764):         var _this = _super.call(this, network) || this;
I/System.out(17764):         errors.checkNew(_this, EtherscanProvider);
I/System.out(17764):         var name = 'invalid';
I/System.out(17764):         if (_this.network) {
I/System.out(17764):             name = _this.network.name;
I/System.out(17764):         }
I/System.out(17764):         var baseUrl = null;
I/System.out(17764):         switch (name) {
I/System.out(17764):             case 'homestead':
I/System.out(17764):                 baseUrl = 'https://api.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'ropsten':
I/System.out(17764):                 baseUrl = 'https://api-ropsten.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'rinkeby':
I/System.out(17764):                 baseUrl = 'https://api-rinkeby.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'kovan':
I/System.out(17764):                 baseUrl = 'https://api-kovan.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'goerli':
I/System.out(17764):                 baseUrl = 'https://api-goerli.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             default:
I/System.out(17764):                 throw new Error('unsupported network');
I/System.out(17764):         }
I/System.out(17764):         properties_1.defineReadOnly(_this, 'baseUrl', baseUrl);
I/System.out(17764):         properties_1.defineReadOnly(_this, 'apiKey', apiKey);
I/System.out(17764):         return _this;
I/System.out(17764):     }
E/AndroidRuntime(17764): FATAL EXCEPTION: Thread-3
E/AndroidRuntime(17764): Process: com.shyftnetwork.wx, PID: 17764
E/AndroidRuntime(17764): TypeError: Object.defineProperty called on non-object
E/AndroidRuntime(17764): 	at org.liquidplayer.javascript.JSFunction.apply(JSFunction.java:416)
E/AndroidRuntime(17764): 	at org.liquidplayer.javascript.JSFunction.call(JSFunction.java:377)

further, re:

let defaultProvider = ethers.getDefaultProvider('ropsten');

Getting that (which does work) and then calling a function on one of its members, I'm getting the following error when using "getProviderBlockNumber" (which should return a promise object, though it crashes before returning the object):

I/System.out(14807):     myProviderObjectFunction ::function () {
I/System.out(14807):         var _this = this;
I/System.out(14807):         return this.ready.then(function () {
I/System.out(14807):             return _this.perform('getBlockNumber', {}).then(function (result) {
I/System.out(14807):                 var value = parseInt(result);
I/System.out(14807):                 if (value != result) {
I/System.out(14807):                     throw new Error('invalid response - getBlockNumber');
I/System.out(14807):                 }
I/System.out(14807):                 _this._setFastBlockNumber(value);
I/System.out(14807):                 return value;
I/System.out(14807):             });
I/System.out(14807):         });
I/System.out(14807):     }
E/AndroidRuntime(14807): FATAL EXCEPTION: Thread-3
E/AndroidRuntime(14807): Process: com.shyftnetwork.wx, PID: 14807
E/AndroidRuntime(14807): TypeError: Cannot read property 'ready' of null
E/AndroidRuntime(14807): 	at org.liquidplayer.javascript.JSFunction.apply(JSFunction.java:416)
E/AndroidRuntime(14807): 	at org.liquidplayer.javascript.JSFunction.call(JSFunction.java:377)

If you could point me to a framework example which work in this case, that would be excellent.

q1) Why would getting a JSObject of the type "new" have internal issues referencing itself? q2) How do I get a promise object returned without it crashing inside of the function call?

I'm assuming these issues are directly related?

Thanks for your help, I'd vastly prefer understanding how your microservices work and then extending the same mechanisms in the IOS realm rather than patching together different implementations on various platforms.

Fyi: I'm using the format:

var service = MicroService(this@MainActivity, uri, startListener)

where in the service object I'm starting a new Thread inside of the onStart function, and then running the code that results in the errors referenced above inside of the "run" of the Runnable (which I'm assuming maintains the object references to the various JSObjects, as I thought that may have been the issue with the "new" objects)

LiquidPlayer/LiquidCore

Answer questions ericwlange

Please try the latest version of LiquidCore (0.7.5+) and see if this is still a problem. IPFS seems to work ok, which uses ethereum. Please re-open if there is still a problem.

useful!

Related questions

No questions were found.
Github User Rank List