web3 / web3.js Goto Github PK
View Code? Open in Web Editor NEWCollection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
Home Page: https://web3js.org/
License: Other
Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
Home Page: https://web3js.org/
License: Other
I pass the transact function two parameter say: "0xf34926b54a83a89934e7034b5b5865cd8e99b220" and "5000" with a function id of 0. This creates the below transaction and discards the 132 LSB :
e9e8c4c57cdee43ea0da8bd400584a39e916088ce179cd517c797c42e6dfc88c
From: 8ad211c31afb337c465ab1b07813a52662cd59e0
To: c9923753f8c56c9d9ff8c60da6171252505d8e07
Value: 0 wei #81
Gas price: 10000 Gwei
Gas: 145983
0000 ??????????????I& 00 00 00 00 00 00 00 00 00 00 00 00 00 f3 49 26
0010 ?J?????????????? b5 4a 83 a8 00 00 00 00 00 00 00 00 00 00 00 00
0020 ???????????????? 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0030 ???????????????? 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13
0040 ? 88
I am not sure if this is a bug or something I am doing incorrectly when I create the 'contract' object. In my description I am declaring the input parameters as type uint256 as this code was created in serpent. There is no documentation on 'contract' objects so I am not sure if I am doing this right..
When the coinbase balance is 0, the https://github.com/ethereum/ethereum.js/blob/master/example/balance.html example shows NaN
. Instead I'd expect it would show 0
. This is with the JSONRPC interface connecting to eth
running develop build ethereum/aleth@c3b6fdd.
Most likely web3.toDecimal(balance)
should return 0
if balance
is 0x
; or the JSONRPC API should be modified to return 0x0
instead of 0x
.
(I'm cross-posting this to go-ethereum, 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?
I've created a folder called 'eth' and a folder called 'node_modules' within it. I run
npm install ethereum.js
from within 'eth' and ethereum.js is installed to node_modules.
Running a simple test.js file containing
require('web3'); console.log('hiya');
returns the error
Cannot find module 'web3'
Are there any workarounds for this?
If i add multiple watcher()
callback from different filter, they all fire, if a message arrives.
I seem to have stumbled upon a mixup in the role of ethereum.js
, with important security connotations. It seems it is being used for the following two purposes:
Note: here I define Dapp
as any html document with web3
exposed in its javascript context
While there is a lot of overlap between these two roles, there is an important difference. The UI is a privileged entity and the Dapp must be assumed to be a malicious entity (just like any webpage on the internet). As it currently stands we are exposing some sensitive things to a potentially malicious Dapp.
The primary vulnerability is an attacker sending themselves ether.
web3.eth.sendTransaction({
to: $AddressOfAttacker,
from: web3.eth.coinbase,
value: $amountInVictimsAccount,
})
Another attack is retargeting the client's coinbase to their own.
web3.eth.coinbase = $AddressOfAttacker
web3.eth.mining = true
Since 422dc05
Trying example/balance.html
gives the following error:
TypeError: undefined is not a constructor (evaluating 'new web3.providers.QtProvider()')
This is with Mist 0.8.1 (go1.4.1) on OSX, commit 06bfe19f05b2a961a458cada69c72c809354f53f and Ethereum.JS commit 6a58db6
e.g. gas is an integer and must be passed as such (e.g. web3.eth.transact({gas: '69'}) is wrong); whereas gasPrice is a string (e.g. web3.eth.transact({gasPrice: 69}) is wrong)
this is no good. so let's make everything a string in the JSONRPC - no integers there at all. so it'll correctly accept integers, BigIntegers, decimal strings and 0x-prefixed hex strings.
Hey! Not sure if this is the right place to ask (perhaps the forum is better?). #ethereum-dev isn't very lively. :). Will try here first.
When connecting to the c++ client (haven't tried this with go-ethereum), the garbage collector removes watches after 20 seconds. Looking at cpp-ethereum, it is made to do that (removes any watches that haven't been polled in 20 seconds). (https://github.com/ethereum/cpp-ethereum/blob/a783bbb5063fcc208fb8e85fc036e90eab1ae186/libethereum/Client.cpp#L601).
However, in the JS API, the polling is done every second. Is there a problem here where it doesn't connect to the cpp client to properly refresh the "lastPoll"? Or is this intended?
(Note: The event firing works properly, it's just that after 20 seconds, the watch gets garbage collected)
[20/12/14 20:39:52] gavofyork: there used to be sha3 in the API
[20/12/14 20:39:54] gavofyork: can't see it any more
[20/12/14 20:41:22] gavofyork: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3sha3
[20/12/14 20:41:25] gavofyork: where did it go?
[20/12/14 20:43:41] marek kotewicz: i removed that accidentally and realised that after some time, i will fix that
Executing the below in the JS console:
var source = "" +
"contract test {\n" +
" function multiply(uint a) returns(uint d) {\n" +
" return a * 7;\n" +
" }\n" +
"}\n";
var compiled = web3.eth.solidity(source);
var address = web3.eth.transact({code: compiled});
console.log(address);
Produces:
Error: NETWORK_ERR: XMLHttpRequest Exception 101
code: 101
constructor: XMLHttpRequestExceptionConstructor
line: 1063
message: "NETWORK_ERR: XMLHttpRequest Exception 101"
name: "NETWORK_ERR"
stack: "send@[native code]↵send↵send↵↵eval code↵eval@[native code]↵evaluate@[native code]↵_evaluateOn↵_evaluateAndWrap↵evaluate"
proto: XMLHttpRequestExceptionPrototype
This function is also causing a lot of problems within the GUI
Hi, I detailed the changes needed and implemented them in some gists in this forum post: http://forum.ethereum.org/discussion/1784/my-working-steps-go-ethereum-cli-json-rpc-chrome-browser-etherum-js-solidity#latest
...just wanted to share them here in case it saves you guys some effort.
Hi.
I'm using to fetch ethereum.js. Firstly, it seems to be @cubedro's repo (not this one), and there aren't any version tags.
Would be nice to set a version in bower.json to ensure if someone else wants to develop, they don't download another version of ethereum.js that might not be compatible.
bower ethereum.js#0.0.15 not-cached git://github.com/cubedro/ethereum.js.git#0.0.15
bower ethereum.js#0.0.15 resolve git://github.com/cubedro/ethereum.js.git#0.0.15
bower ethereum.js#0.0.15 ENORESTARGET No tag found that was able to satisfy 0.0.15
Additional error details:
No versions found in git://github.com/cubedro/ethereum.js.git
Hi, your README suggests using providers.WebSocketProvider, but this function was removed recently (at lease it no longer exists in the ethereum.js in the repo's "dist" folder)
Is there still a way to connect to the go ethereum websocket? If not, what is now the proper procedure for connecting to the go ethereum CLI? (Exact info would be helpful, like what go ethereum args are needed, and what port # is used, and what new connection function should be used...)
The property web3.eth.account
seems deprecated/removed in favour of web3.eth.accounts
in both the cpp and go clients; as such it should be removed from the API to prevent confusion.
When calling myWatcher.trigger()
on watcher I get the follwing error
TypeError: Cannot read property 'length' of undefined
at Filter.trigger (http://localhost:3000/client/lib/thirdparty/ethereum.js?39192deaa76f7409badd6acbde24cd4f76159399:611:37)
Running the balance.html example, I get the following warning in Chrome 40.0.2214.91 on OSX:
httpsync.js:62
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects
to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
need to be able to call contracts where some input parameters are arrays.
please add an example too, or extend
https://github.com/ethereum/ethereum.js/blob/develop/example/contract.html
add method to reset web3 object (watches... etc.)
Is there a way such issues are already being tracked, so that they are not forgotten among all the activity that will happen during genesis launch?
https://github.com/ethereum/ethereum.js/blob/develop/lib/web3.js#L168
var desc = [
{
"constant" : false,
"inputs" : [
{
"name" : "street_address_1",
"type" : "string"
},
{
"name" : "street_address_2",
"type" : "string"
},
{
"name" : "contact_phone",
"type" : "string"
},
{
"name" : "contact_email",
"type" : "string"
},
{
"name" : "tax_id",
"type" : "string"
},
{
"name" : "signing_address",
"type" : "address"
}
],
"name" : "registerCustodian",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "custodian_id",
"type" : "uint"
}
],
"name" : "getCustodian",
"outputs" : [
{
"name" : "custodian",
"type" : "struct Custodian"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "hasActiveSmartContract",
"outputs" : [
{
"name" : "has_active_contract",
"type" : "bool"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "property_id",
"type" : "uint"
}
],
"name" : "getProperty",
"outputs" : [
{
"name" : "property",
"type" : "struct Property"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "signAsAuditor",
"outputs" : [
{
"name" : "success",
"type" : "bool"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "getCertificate",
"outputs" : [
{
"name" : "cert",
"type" : "struct Certificate"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
},
{
"name" : "smart_contract_address",
"type" : "address"
}
],
"name" : "activateSmartContract",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "getPropertyType",
"outputs" : [
{
"name" : "property_type_id",
"type" : "uint"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "property_id",
"type" : "uint"
},
{
"name" : "custodian_id",
"type" : "uint"
},
{
"name" : "ca_id",
"type" : "uint"
},
{
"name" : "owner",
"type" : "address"
}
],
"name" : "registerCertificate",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "requestSignature",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "auditor_id",
"type" : "uint"
}
],
"name" : "getAuditor",
"outputs" : [
{
"name" : "auditor",
"type" : "struct Auditor"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "hasValidSignatures",
"outputs" : [
{
"name" : "valid",
"type" : "bool"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "id",
"type" : "uint"
},
{
"name" : "street_address_1",
"type" : "string"
},
{
"name" : "street_address_2",
"type" : "string"
},
{
"name" : "contact_phone",
"type" : "string"
},
{
"name" : "contact_email",
"type" : "string"
},
{
"name" : "tax_id",
"type" : "string"
},
{
"name" : "signing_address",
"type" : "address"
}
],
"name" : "registerCertificateAuthority",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "signAsCustodian",
"outputs" : [
{
"name" : "success",
"type" : "bool"
}
]
},
{
"constant" : false,
"inputs" : [
{
"name" : "owner",
"type" : "address"
},
{
"name" : "property_type_id",
"type" : "uint"
},
{
"name" : "precious_metal_id",
"type" : "uint"
},
{
"name" : "precious_metal_original_weight",
"type" : "uint"
},
{
"name" : "description",
"type" : "string"
}
],
"name" : "registerProperty",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "street_address_1",
"type" : "string"
},
{
"name" : "street_address_2",
"type" : "string"
},
{
"name" : "contact_phone",
"type" : "string"
},
{
"name" : "contact_email",
"type" : "string"
},
{
"name" : "tax_id",
"type" : "string"
},
{
"name" : "signing_address",
"type" : "address"
}
],
"name" : "registerAuditor",
"outputs" : []
},
{
"constant" : false,
"inputs" : [
{
"name" : "cert_id",
"type" : "uint"
}
],
"name" : "signAsCertificateAuthority",
"outputs" : [
{
"name" : "success",
"type" : "bool"
}
]
}
];
var contract = web3.eth.contract("0xe4ed4751a2b366106a05185c7534d87143f48621", desc);
contract.registerProperty(["16e27e57e73bf8eb2b14579e9a573a0a30c84218", 1, 1, 1000, "Something Cool"]).call();
PoC 8 blockchain.
Getting the error on line 74 of abi.js on both develop and master
currently you need to convert it to .toDecimal()
.
I talked to gav and one should be able to pass HEX values.
When calling eth_balanceAt
, cpp-ethereum returns a hexidecimal string, while the go-ethereum client returns a string with a decimal number inside. The laters fails when converting this to a decimal in the https://github.com/ethereum/ethereum.js/blob/master/example/balance.html example.
A new identity can only be verified using toDecimal e.g.:
var myid = web3.shh.newIdentity()
web3.shh.haveIdentity(web3.toDecimal(myid));
Which returns TRUE
I'm interested in creating a provider via a stream.
var streamProvider = new web3.providers.StreamProvider()
remoteDuplexStream.pipe(streamProvider).pipe(remoteDuplexStream)
var web3.setProvider(streamProvider)
would you accept this feature if I opened a PR
This shouldn't result in an error. It's perfectly fine to return "undefined" from eth.transaction(num, i)
for example
Will 'web3.eth.transact' be grandfathered in or are we all sold on 'web3.eth.sendTransaction'? Also when is fromWei and toWei being moved into master branch, any schedule on that (excuse the impatience)?
When running gulp build
after 123098c:
$ gulp build
[12:09:03] Using gulpfile ~/Projects/ethereum/ethereum.js/gulpfile.js
[12:09:03] Starting 'lint'...
/Users/mids/Projects/ethereum/ethereum.js/lib/abi.js: line 49, col 12, Missing 'new' prefix when invoking a constructor.
1 error
/Users/mids/Projects/ethereum/ethereum.js/lib/autoprovider.js: line 38, col 9, 'web3' is not defined.
/Users/mids/Projects/ethereum/ethereum.js/lib/autoprovider.js: line 47, col 29, 'web3' is not defined.
/Users/mids/Projects/ethereum/ethereum.js/lib/autoprovider.js: line 61, col 33, 'web3' is not defined.
/Users/mids/Projects/ethereum/ethereum.js/lib/autoprovider.js: line 63, col 33, 'web3' is not defined.
4 errors
/Users/mids/Projects/ethereum/ethereum.js/lib/contract.js: line 50, col 28, 'web3' is not defined.
/Users/mids/Projects/ethereum/ethereum.js/lib/contract.js: line 56, col 28, 'web3' is not defined.
2 errors
/Users/mids/Projects/ethereum/ethereum.js/lib/main.js: line 265, col 65, Expected '===' and instead saw '=='.
/Users/mids/Projects/ethereum/ethereum.js/lib/main.js: line 276, col 95, Don't make functions within a loop.
/Users/mids/Projects/ethereum/ethereum.js/lib/main.js: line 277, col 21, Expected '===' and instead saw '=='.
3 errors
[12:09:04] Finished 'lint' after 266 ms
[12:09:04] Starting 'clean'...
[12:09:04] Finished 'clean' after 2.4 ms
[12:09:04] Starting 'build'...
events.js:72
throw er; // Unhandled 'error' event
^
Error: Parse Error: Line 29: Unexpected token * while parsing file: /Users/mids/Projects/ethereum/ethereum.js/lib/websocket.js
contract.html line 46 returns an empty object.
I get a contract (which doesn't exist, or i can't know if it exists) and want to watch for an event.
If have the following ABI:
{
"name":"SingleTransact",
"type":"event",
"inputs":[
{"indexed":true,"name":"out","type":"string32"},
{"indexed":false,"name":"owner","type":"address"},
{"indexed":false,"name":"value","type":"uint256"},
{"indexed":false,"name":"to","type":"address"}
]
}
And i watch for that event like:
var singleTxWatcher = contract.SingleTransact();
singleTxWatcher.changed(transactionCallback);
I get the following error: Uncaught TypeError: Cannot read property 'length' of undefined ethereum.js:1050
Which matches the following part in ejs:
var web3 = {
_callbacks: {},
_events: {},
providers: {},
toHex: function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
},
...
https://github.com/ethereum/ethereum.js/blob/master/lib/httprpc.js#L26
This line inadvertently causes some problems when using ethereum.js with browserify.
Though we're in the browser, XMLHttpRequest
gets overridden with xmlhttprequest
module's version.
This would be fine, but it has a bug where it behaves as if xhr.withCredentials
is set to true
.
This disables wildcard ('*') CORS headers. Which is annoying.
Hi, I have a simple contract:
contract SuperProject {
int8 index;
function getNumber() returns (int8) {
int8 next = index++;
return next;
}
}
Now, I want to get that number in JS.
var ABI = [{"constant":false,"inputs":[],"name":"getNumber","outputs":[{"name":"","type":"int8"}],"type":"function"}];
var contractAddress = "0x11111222222222222222";
var contract = web3.eth.contract(contractAddress, ABI);
contract.call().getNumber();
That returns me this:
t {s: 1, e: 0, c: Array[1], abs: function, absoluteValue: function…}
Can anybody tell me how to properly interrogate the contract?
I get CORS errors when i want to connect to eth
node started with $ eth -j -b -f -n no -m yes
in safari:
[Error] XMLHttpRequest cannot load http://localhost:8080/. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.
send (ethereum.js, line 660)
send (ethereum.js, line 746)
(anonymous function) (ethereum.js, line 967)
(anonymous function) (whisperConnector.js, line 16)
global code (whisperConnector.js, line 208)
[Error] Failed to load resource: Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. (localhost, line 0)
The RPC endpoint should return CORS headers, probably even for OPTIONS pre-flight requests.
Works in chrome, thought...
This should probably go to the CPP repo?
Using latest Ethereum.js (from develop).
When I do:
var eventFilter = web3.eth.filter(testContract.Event);
Says "filter" is an undefined function.
Similar
web3.eth.filter('pending').watch(function(res) {
//do stuff
});
It's not getting filter().
i'm getting a cross-domain issue when using the HttpSyncProvider. are we not using a jsonp technique here to allow different origins?
i'm trying to develop a UI that will probably be hosted from a CDN or external source and connect to the local ethereum client. websockets i understand are being deprecated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.