Cannot access web3 object with typescript and ethereum

0 votes

I started a new project from scratch with angular 2 and typescript with:

ng new myProject

Then I installed web3 (for ethereum) with

npm install web3

In the head of index.html, I added:

<script src="node_modules/web3/dist/web3.min.js"></script>

This path seems OK since I have no error (if I change one char I have an error). In the doc: I found this: Use the web3 object directly from global namespace: console.log(web3); But web3 is not defined. How can I get this object ?

Sep 25, 2018 in Blockchain by digger
• 26,720 points

1 answer to this question.

0 votes

You still need to instantiate it first. Tested with JavaScript:

var web3 = new Web3();
> Object { _requestManager: Object, currentProvider: undefined, eth: 
    Object, db: Object, shh: Object, net: Object, personal: Object, bzz: 
    Object, settings: Object, version: Object, 2 more }
answered Sep 25, 2018 by slayer
• 29,310 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

How can I inject and use this javascript library (web3) with JavascriptCore

The web3.js library has dependencies on bignumber.js and crypto-js.js (See dependencies here). You will ...READ MORE

answered Oct 8, 2018 in Blockchain by Omkar
• 69,150 points
+1 vote
1 answer

Getting issues while Sending signTransaction with web3.js

The chain ID for ropsten is 3. ...READ MORE

answered Mar 28, 2018 in Blockchain by Johnathon
• 9,090 points
+2 votes
1 answer

Blockchain declining my API key and I cannot understand why.

It's quite easy. Request the API key using ...READ MORE

answered Apr 3, 2018 in Blockchain by Christine
• 15,830 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,830 points
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
0 votes
1 answer

How to access member functions of smart contract using web3?

I have implemented a similar feature and ...READ MORE

answered Aug 13, 2018 in Blockchain by slayer
• 29,310 points
0 votes
2 answers

How do I interact with a smart contract on a private network through web3.js

I found a blog that explains how ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,310 points