ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.28k stars 20.01k forks source link

Connecting ethereum.js and go-ethereum -- MagicToken mismatch? #276

Closed tinybike closed 9 years ago

tinybike commented 9 years ago

(I'm cross-posting this to ethereum.js, since it seems to pertain to both, from my limited vantage point.)

I've been tinkering with the JS API, trying to figure out how to compile contracts (and actually load them into the blockchain). The example here is using Serpent code, but I get the same error when using Solidity instead.

I'm running go-ethereum, started as ethereum -rpc -loglevel=4 -y. If I define a variable w/ some simple serpent code:

var serp = "def double(v):\n" +
"   return(v*2)"

Then from my browser (Chrome) console:

> web3.eth.serpent(serp)
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}

But, it just stays in "pending" forever. On the backend, I get the following message:

2015/01/26 23:48:58 [PEER] MagicToken mismatch. Received [80 79 83 84]

I'm not clear what this means -- what is a MagicToken? I googled and found https://gogs.io/github.com/eris-ltd/go-ethereum/wire, which says:

var MagicToken = []byte{34, 64, 8, 145}

"The magic token which should be the first 4 bytes of every message and can be used as separator between messages." I tried using this in Solidity:

var source = "[]byte{34, 64, 8, 145};" + 
"contract test {\n" +
"   function multiply(uint a) returns(uint d) {\n" +
"       return a * 7;\n" +
"   }\n" +
"}\n";
web3.eth.solidity(source);

but I get the same MagicToken error. What am I doing wrong?

obscuren commented 9 years ago

The current version of go-ethereum's JSON RPC is using TCP/IP and will therefor not work in your browser. We're currently converting the RPC to HTTP and should probably be ready by the end of the week (will update this issue).

It also appears you're using a very old version of ethereum. Please update to develop branch

tinybike commented 9 years ago

Got it. Can a browser talk to go-ethereum via websockets? (Was avoiding websockets since as I understand it they're not yet supported in cpp-ethereum, but...)

obscuren commented 9 years ago

Yes it's supported -ws. Please be aware that web sockets support might drop. We're in the processes of changing to a fully synchronous JavaScript API rather than asynchronous

tinybike commented 9 years ago

Hm, looks like ethereum.js's latest version no longer has providers.WebSocketProvider...strange.

scottzer0 commented 9 years ago

yea, so as i understand it, ethereum.js has dropped websocket support in favor of http sync and go-ethereum has yet to implement http?

i'm chomping at the bit to start UI dev on our project...

obscuren commented 9 years ago

@scottzer0 We've HTTP, it's not yet merged and doesn't support all calls.