GithubHelp home page GithubHelp logo

web3 / web3.js Goto Github PK

View Code? Open in Web Editor NEW
18.8K 18.8K 4.8K 131.51 MB

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.

Home Page: https://web3js.org/

License: Other

JavaScript 2.96% TypeScript 96.46% Shell 0.35% Solidity 0.16% HTML 0.07%
abi-decoders abi-encoders api ethereum javascript typescript web3 web3js

web3.js's People

Contributors

avkos avatar cgewecke avatar chevdor avatar cruzmolina avatar cubedro avatar debris avatar dependabot[bot] avatar ethers avatar ewingrj avatar frankiebee avatar frozeman avatar gabmontes avatar gavofyork avatar gregthegreek avatar holgerd77 avatar jdevcs avatar kumavis avatar lefterisjp avatar luu-alex avatar mpetrunic avatar muhammad-altabba avatar nachomazzara avatar nazarhussain avatar nikoulai avatar nivida avatar obscuren avatar princesinha19 avatar ryanio avatar santiagodevrel avatar spacesailor24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

web3.js's Issues

CORS headers are missing on RPC cpp endpoints

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?

gulp build failing

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

Synchronous XMLHttpRequest warning in Chrome

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/.

Trying to connect to WebSocketProvider, but function has been removed from repo

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...)

Contract event returns error, if the contract doesn't exist.

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;
    },
...

calling a contract function from js API

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?

StreamProvider

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

XMLHttpRequest cannot load http://127.0.0.1:30303/

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.

TypeError: Cannot read property 'indexOf' of undefined

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

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

(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?

Add sha3 back in

[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

unify JSON-RPC && ethereum.js integer input params

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.

Cannot find module 'web3'

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?

Garbage collector & polling?

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)

ethereum.js and security

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:

  • (1) UI and ethereum-client communication
  • (2) Dapp's access to the blockchain

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

Version tags for Bower?

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

shh.watcher.trigger() doesn't work

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)

Filter undefined?

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().

Will web3.eth.transact still work?

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)?

Transact() seems to discard the LSB of parameters passed to it.

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..

web3.eth.transact is not returning any value

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

Remove web3.eth.account

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.