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:https://www.npmjs.com/package/web3 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,740 points
2,647 views

1 answer to this question.

0 votes

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

var web3 = new Web3();
window.console.log(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,350 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,210 points
771 views
0 votes
1 answer
0 votes
1 answer

How to swap an Ethereum ERC-20 and Neo NEP5 token with a smart contract?

Each blockchain is its own separated administration. ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,700 points
573 views
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,790 points
1,679 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,224 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,138 views
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,350 points
1,392 views
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,350 points
3,670 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP