web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.27k stars 4.94k forks source link

using web3 object on meteor server side code? #381

Closed hems closed 8 years ago

hems commented 8 years ago

I'm trying to use web3 from the server as i wish the server side code to do the interaction with the blockchain, so i can keep my application "transparent" to users, but web3 is undefined after adding this package.

my installation was simply: meteor add ethereum:web3

Any suggestions ?

frozeman commented 8 years ago

Did you try this https://github.com/ethereum/wiki/wiki/JavaScript-API#adding-web3

var Web3 = require('web3');

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
hems commented 8 years ago

i tried meteor add ethereum:web3 but web3 still undefined on the server, is that the expected behaviour ?

should i require it through npm ?

hems commented 8 years ago

Even though i can see web3 @package.json is supposed to export to the server, i still get it undefined on meteor server code.

tests/embark [ meteor --version              
tests/embark * ] 2:41 am
Meteor 1.1.0.2

tests/embark [ node --version
tests/embark * ] 2:41 am
v1.2.0

# server/app.js
Meteor.startup( function(){

  console.log("Server started")

  console.log( "web3 ->", web3 )
})
W20160202-02:39:42.052(0)? (STDERR) ReferenceError: web3 is not defined
W20160202-02:39:42.052(0)? (STDERR)     at app/server/embark.js:1:36
W20160202-02:39:42.052(0)? (STDERR)     at app/server/embark.js:3:3
W20160202-02:39:42.052(0)? (STDERR)     at /Volumes/backpack/git/xxx/tests/embark/.meteor/local/build/programs/server/boot.js:222:10
W20160202-02:39:42.052(0)? (STDERR)     at Array.forEach (native)
W20160202-02:39:42.052(0)? (STDERR)     at Function._.each._.forEach (/Users/hems/.meteor/packages/meteor-tool/.1.1.3.pfjq9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20160202-02:39:42.052(0)? (STDERR)     at /Volumes/backpack/git/xxx/tests/embark/.meteor/local/build/programs/server/boot.js:117:5
frozeman commented 8 years ago

The Web3 object is available (uppercase).

You need to instantiate it first. See the veering started guide on the web3.js docs page in the wiki.

On 01.02.2016, at 18:38, henrique matias notifications@github.com wrote:

i tried meteor add ethereum:web3 but web3 still undefined on the server, is that the expected behaviour ?

should i require it through npm ?

— Reply to this email directly or view it on GitHub.

hems commented 8 years ago

@frozeman ooooooh gosh. my bad!

where is my n00b badge? ( :

parthi2929 commented 6 years ago

Hi In case of local testrpc its ok. but how to use testnet like rinkeby

kn1g commented 6 years ago

try geth --rinkeby --rpc --rpcapi db, eth, net web3, personal --unlock="YOURACCOUNT"

e.g. geth --rinkeby --rpc --rpcapi db, eth, net web3, personal --unlock="0x876h54e45hz..."

still use: var Web3 = require('web3'); web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));