Comments (26)
I'm not sure if it's necessary, but can you also check the version of web3 in package-lock.json (the direct dependency, not the dependency of one of the others)
from angular-truffle-box.
"web3": {
"version": "1.0.0-beta.24",
"resolved": "https://registry.npmjs.org/web3/-/web3-1.0.0-beta.24.tgz",
"integrity": "sha1-C2U9alD0B7N/WTNx+27hvTofJ8I=",
"dev": true,
"requires": {
"web3-bzz": "1.0.0-beta.22",
"web3-core": "1.0.0-beta.24",
"web3-eth": "1.0.0-beta.24",
"web3-eth-personal": "1.0.0-beta.24",
"web3-net": "1.0.0-beta.24",
"web3-shh": "1.0.0-beta.24",
"web3-utils": "1.0.0-beta.24"
}
},
from angular-truffle-box.
I've pushed a fix at https://github.com/Quintor/angular-truffle-box/tree/bugfix/remove-web3-dep
Can you check out that branch and see if it works? (I can't imagine it doesn't, as this removes the entire web3 dependency)
from angular-truffle-box.
So if you remove this dependency, does it mean it uses the same web3 as the one depended on by truffle-contract and so on?
from angular-truffle-box.
Ehm, it uses the provider that's tagged on to the version embedded in MetaMask, and I suspect truffle wraps that provider with it's own version of web3, but I haven't checked that
from angular-truffle-box.
I mean in web3.service.ts
from angular-truffle-box.
Anyway, now the compiler seems happy, but I have another weird error. Instead of checking out your branch, I simply removed the dependency in package.json, deleted package-lock.json and node_modules and re-installed depedencies. But now when I try to compile my contracts, I have another weird error:
Error: Cannot find module 'require-from-string'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/truffle/node_modules/solc/wrapper.js:2:25)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
Does that ring a bell to you?
from angular-truffle-box.
Yeah, so previously I would instantiate a new Web3 instance with the provider on the page, then use that instance to get the provider and use the .eth.getAccounts function. Now, I skip the step of creating the new instance and just use the MetaMask-exposed version directly.
from angular-truffle-box.
Will this still work if the page is loaded in something like Mist?
from angular-truffle-box.
I've never tried it, but I'm pretty sure Mist injects web3 in the same way, but I've never checked, because when I looked I couldn't find a working version of Mist
from angular-truffle-box.
OK, so I'm still left with my truffle compile error above. I'll investigate, thanks.
from angular-truffle-box.
Since the truffle compile is from the globally installed truffle you might try reinstalling that.
from angular-truffle-box.
Reinstalling truffle solved my problem, but I'm not super comfortable with your change that removed the dependency on web3 entirely, since a lot of your code in the Web3Service class is counting on the fact that it's there. For example, this part of the code assumes that we are connecting to web3 1.0, doesn't it?
private refreshAccounts() {
this.web3.eth.getAccounts((err, accs) => {
if (err != null) {
alert('There was an error fetching your accounts.');
return;
}
// Get the initial account balance so it can be displayed.
if (accs.length === 0) {
alert('Couldn\'t get any accounts! Make sure your Ethereum client is configured correctly.');
return;
}
if (!this.accounts || this.accounts.length !== accs.length || this.accounts[0] !== accs[0]) {
console.log('Observed new accounts');
this.accountsObservable.next(accs);
this.accounts = accs;
}
this.ready = true;
});
}
This asynchronous call to web3.eth.accounts looks very 1.0-ish to me.
from angular-truffle-box.
Mmm. You do have a point. So maybe we should be wrapping it after all? Or do you have another idea? The thing is that https://github.com/Quintor/angular-truffle-box/tree/bugfix/remove-web3-dep suggests that the current usage will be broken, but the way it used to be looked kind of sketchy as well.
from angular-truffle-box.
No other idea at this point. I just think we should be able to control which version of web3 we are using, especially in these times of such great upcoming change in web3's API.
from angular-truffle-box.
I've reverted the changes and pinned web3.js to 1.0.0-beta.23 which doesn't seem to have the problem you've experienced. The style of import we're using was also causing some issues when I tried to test, so if you have thoughts on that, they are very welcome.
from angular-truffle-box.
Did you push your changes? Because I can't see it right now. And I can confirm that the MetaCoin sample was not working at all.
from angular-truffle-box.
from angular-truffle-box.
Weird because the latest commit I see on this repository is this one, the one you made about 15 hours ago to remove the dependency on web3: 242eec6
from angular-truffle-box.
My bad, you're right. I pushed now. This should fix the issues for now, but we should be looking into why the import is failing in 1.0.0-beta.24, in case that makes it into the definitive 1.0.0 release of web3. Or possibly use the truffle included web3 to abstract?
from angular-truffle-box.
I think it would make sense to create an angular-web3 wrapper around web3 that would be independent from the angular-truffle-box project. We could include some abstractions like your Web3Service and so on. And it could be imported in the angular-truffle-box as a dependency, or used in any existing Angular project. What do you think?
from angular-truffle-box.
I think conceptually it's a good solution, but I'm not sure what the interface would be. Would it just be an service that provides a Web3? How would we hook the contract abstractions, which are application dependent?
from angular-truffle-box.
Not sure either but I'll look into it as I'm working on my own sample application for the Devoxx conference where we would like to showcase your box. I'll create pull requests as I move forward.
from angular-truffle-box.
I just created a first pull request simply to clean up the code of the box and remove all the warning that IntelliJ and tslint were giving me: #5
from angular-truffle-box.
Awesome:)
I've made some issues for stuff that has been on my backlog, but I haven't gotten to. Feel free to create issues of what you're working on so that there's no double work done
from angular-truffle-box.
Fixed with #11
from angular-truffle-box.
Related Issues (20)
- Trouble unboxing package HOT 7
- ERROR TypeError: web3_1.default is not a constructor HOT 5
- TypeChain HOT 10
- Error HOT 4
- Create Dockerfile HOT 1
- web3_1.default is not a constructor HOT 18
- Event example HOT 2
- Use Ganache instead of TestRPC HOT 4
- Updating angular cli to version 1.6.2 causes karma tests to fail HOT 2
- When try to unbox, can't find Python executable even it is already installed HOT 4
- Error: Contract has not been deployed to detected network (network/artifact mismatch) HOT 2
- Upgrade to angular 6.0 HOT 2
- Having trouble unboxing this box HOT 2
- Update to Angular 7 HOT 1
- accounts balance happend but dont refresh on ganache or metamask HOT 5
- Remove node-gyp subdependencies
- Revisit web3 integration
- truffle unbox Quintor/angular-truffle-box command problems HOT 3
- this truffle cant work with Metamask since this year (Chrome) HOT 1
- Unbox failing on windows 10 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-truffle-box.