Hot answers tagged

29

For web3 0.x: You need to use web3.fromAscii(val) to write correct bytes32 input to contract. And you are right, anyone can read it with web3.toAscii(val). Full web3.js code in terms of your designations: //sets bytes32 testInstance.test.sendTransaction(web3.fromAscii("20160528"), options); //gets bytes32 testInstance.Date.call(function(err, val) { ...


25

Solution: MyContract = new web3.eth.Contract(abi) Docs https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract When using version 1.0.x you need to pass in the Application Binary Interface, i.e. abi. And use the new keyword.


18

I assume that you are attempting to connect to a geth node. It might be that this node does not have the personal management API loaded which you could specify while starting geth --rpcapi eth,web3,personal --rpc as described. Please take care, everyone with (local) access to your machine could now mess with your accounts, therefore this is disabled by ...


16

Here is my deploy script that also handles waiting until the transaction is included in a block: // Copyright 2017 https://tokenmarket.net - MIT licensed // // Run with Node 7.x as: // // node --harmony-async-await deploy.js // let fs = require("fs"); let Web3 = require('web3'); // https://www.npmjs.com/package/web3 // Create a web3 connection to a ...


16

This can be accomplished with a simple wrapper: const promisify = (inner) => new Promise((resolve, reject) => inner((err, res) => { if (err) { reject(err) } resolve(res); }) ); To use it, just wrap your web3 calls as follows: const accounts = await promisify(cb => web3.eth.getAccounts(cb)); If you want to promisify ...


16

I'm using web3.js version: 0.20.1 in node.js express application. I'm running Parity in Virtualbox Ubuntu machine. The correct code looks like following: var count = web3.eth.getTransactionCount("0x26..."); var abiArray = JSON.parse(fs.readFileSync('mycoin.json', 'utf-8')); var contractAddress = "0x8..."; var contract = web3.eth.contract(abiArray).at(...


15

It'd probably go something like this: User wants to deposit a token to your exchange If it's the first time the user is depositing that token then this occurs: Generate a new wallet key/pair on the server side Encrypt the private key with a secret/salt only known by the server and store the encrypted private key and public address in your database, along ...


14

When you run truffle migrate, Truffle compiles the contract to a JSON file located into build/contracts/MyContract.json This JSON file can be used by a Node library called truffle-contract like that: // Import libraries var Web3 = require('web3'), contract = require("truffle-contract"), path = require('path') ...


12

(Here is the same response as the one I added to the question referenced above) If I start geth using the following command line: Iota:~ user$ geth --rpc console And I try to execute the following curl command: Iota:~ user$ curl localhost:8545 -X POST --header 'Content-type: application/json' --data '{"jsonrpc":"2.0", "method":"debug_traceTransaction", "...


12

geth-compatible keystore file can be created in Node using ethereumjs-wallet library: > var Wallet = require('ethereumjs-wallet'); > var key = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex'); > var wallet = Wallet.fromPrivateKey(key); > wallet.toV3String('password'); '{"version":3,"id":"467233bf-45ec-423b-...


11

I found many answers which were out of date or were missing important information. Here's what finally worked for me in my node.js project using web3 version 1.0.0-beta.26. Note that this is for Ethereum Main Net. To use the Robsten test net, change the chainId to 0x03 // Get private stuff from my .env file import {my_privkey, infura_api_key} from '../.env' ...


10

from the geth console: admin.startRPC("127.0.0.1", 8545, "*", "web3,db,net,eth") then I was able to reconnect in node, and list the accounts. (unsurprisingly, telnet responded on this port too after starting RPC from within geth) Taken from here: web3 methods not implemented


10

This script has a getTransactionsByAccount. You need to modify it by prepending web3, for example use web3.eth.blockNumber instead of just eth.blockNumber (which works in the Geth console since the Geth console includes the web3 object). Above will give the easy transactions, and more work will be needed for How to get contract internal transactions. In ...


9

If you have installed through npm install -g solc Here's how you use it. solcjs --version


9

Where did your web3 object come from? It needs to be constructed with a Provider that tells it how to connect to an Ethereum node, like this: var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));


9

Let me walk you through the options. I'm assuming you are only requiring the RPC for your users, so either run parity in --public-node mode which disables account storage and transaction signing on your server or disable the wallet with --no-ui. If you really only want to serve RPC, you can not only disable --no-ui but also the websocket with --no-ws and ...


9

I found the problem with the help of @num8er so I will document the issue here: I used the BlockCypher API service to generate the key pairs. What I did not notice, is that Blockcypher removes the 0x from the addresses. When the 0x is not present, web3 generates the incorrect public address. This is why it kept giving me the error "insufficient funds". if ...


9

HD Wallets refer to Hierarchical Deterministic wallets. They are wallets that from a root it can generate multiple "child" private keys in a deterministic way. You only need to remember the "path" of the child key. For example hardware wallets use them from a single root you can generate separate keys for Bitcoin (with path m/44'/0'/0'/0) and Ethereum (path ...


8

If you are not familiar with node.js but with PHP and the ethereum architecture, I recommend you to have a look on the RPC API: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter In particular at eth_newFilter and eth_getFilterChanges which you can simply call via rest API e.g. # This will install a new filter with your desired address curl -X ...


8

EDIT: For other users reading this: The solution is to find in the comments of this answer - launching parameters were wrong. http requests to the node are not supposed to return anything of use, it's totally fine that you get that response in your browser. Assuming you want to develop a dApp for your private chain, i recommend using https://github.com/...


8

I think your main issue is, you are binding only to the localhost address, are you running geth on a remote server? or are you running it on your local machine and also running the mew_relay on the same machine? If you are running your geth on a remote server and running the relay on your local machine id suggest changing to --rpcaddr="0.0.0.0" then try ...


8

If you want to have promises with contracts, have a look at Truffle Artifactor. For the basic asynchronous methods of Web3, I made this Gist: https://gist.github.com/xavierlepretre/90f0feafccc07b267e44a87050b95caa I paste here the version at time of writing: module.exports = { promisify: function (web3) { // Pipes values from a Web3 callback. ...


7

Your handler function may have some error preventing the handler to execute correctly. You can check if "err" got set in your handler and print it to see exactly what error it is. For me if I run your exact code, I had to remove the reference to "account" and change "sendingAddr" to the first address of the keystore before the code runs. Make sure these 2 ...


7

Ethereum offers a Web3 JavaScript Ðapp API To make your Ðapp work on Ethereum, you can use the web3 object provided by the web3.js library. Under the hood it communicates to a local node through RPC calls. web3.js works with any Ethereum node, which exposes an RPC layer. You can use this library as jQuery in any HTML page. To use this is NodeJS web3 is ...


7

Simple transactions are not indexed. So you either need to iterate over all the blocks, use some kind of an off-chain index (e.g. etherscan.io), or build one up yourself and use it. For example, you can use this heuristic approach without having to process the entire chain var myAddr = '0xbb9bc244d798123fde783fcc1c72d3bb8c189413'; var currentBlock = eth....


6

Source Code, Bytecode and Application Binary Interface If you plug your source code contract x { function g() {} } into the left hand pane of the Solidity Online Compiler, you will see on the right hand side a Bytecode text box which contains the binary representation of your source code. This is what output.contracts[contractName].bytecode will contain, ...


6

Before starting: Make sure eth and personal APIs are enabled on your node. For geth you do that with these switches: --rpcapi eth,personal Here is how I did it with web3.js version 1.0: const Web3 = require('web3'); const solc = require('solc'); // For localhost const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); let source = ...


6

In your NodeJS you have to fix the input you are passing to its keccak function. The fix might simply be: keccak_256(firstName+lastName+ studentId); but you have to check your NodeJS library as well as the types you're passing in. Solidity docs: keccak256(...) returns (bytes32): compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) ...


6

As Ismael suggested, setting the web3 version to 0.20.0 in my package.json allowed me to use this code. npm install ethereumjs-testrpc web3@0.20.1 Ideally, I would update my code to work with latest package but happy with this solution for now.


6

As outlined here a nonce "is just a sequential number tied to every transaction that represents the number of transactions the sender account has made on the network" . You have used an arbitrary value defined by yourself, and thus the transaction signature will be invalid. The transaction will thus not be mined. As mentioned by Ismael, you can use ...


Only top voted, non community-wiki answers of a minimum length are eligible