Created
July 12, 2017 22:36
-
-
Save anonymous/6e4f27981c7f6d3bbea66919e39f198a to your computer and use it in GitHub Desktop.
Yeah I'm using Metamask do I need to specify that somehow?
I found this link that talks about adding properties.
Ok I figured it out using (<any>window).MyNamespace
.
Now I'm having trouble with these lines
return this.web3.eth.getBalance(PubAd, function(error, result){
if(!error)
/**console.log(String(result));*/
console.log(this.web3.fromWei(String(result), 'ether'));
else
console.error(error);
})
.map(response =>
response.json()
)
I'm getting two errors
- ERROR TypeError: Cannot read property 'map' of undefined.
- Cannot read property 'fromWei' of undefined
Looks like you're having scoping issues... Look into how scoping works in JavaScript
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting. I'm not sure why that would work, actually.
The problem I see are these two lines:
If you've just defined
localWeb3
, it will never be undefined. The sample code you've pulled from is not supposed to be checking the variable you just created, but is checking to see ifweb3
already exists in the global context--and if so, use thecurrentProvider
it holds, rather than spinning up a new one. This is to allow you to easily use an injectedweb3
context (e.g. Metamask), and then fall back to a standard http/ipc provider (local node) if the injected one doesn't exist.The second one is probably the preferable one, but it's probably failing because Typescript. That doesn't look like a runtime error, but a compile-time error. Perhaps you can look into how Typescript determines which properties are on
window
, and addweb3
to it?