Hot answers tagged

5

This web3 version is a few years old you should probably use a new one. Make sure to update!


3

Thanks for this! Ended up doing: node --stack-size=4096 .\node_modules\truffle\build\cli.bundled.js compile, instead of truffle compile (after taking a look in node_modules/.bin/truffle). EDIT: on Ubuntu this works too: node --stack-size=4096 node_modules/.bin/truffle compile


3

I don't fully understand the question but I think this might help. JavaScript has no type for a 256-bit integer so web3.js includes the bignumber.js library. Web3.js 1.0: https://web3js.readthedocs.io/en/1.0/web3-utils.html?highlight=bignumber#bn Web3.js 0.x: https://github.com/ethereum/wiki/wiki/JavaScript-API#a-note-on-big-numbers-in-web3js To avoid ...


3

Did you try web3's web3.eth.personal.ecRecover? For example, if you sign via web3.eth.personal.sign("Hello world", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "test password!") .then(console.log); > "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400" You "recover" via....


3

It is very simple, const Web3 = require('web3') const web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/Your API key here#")); async function createAccount(){ var wallet = await web3.eth.accounts.create(); console.log('Address:' + wallet.address); console.log('Private Key: ' + wallet.privateKey) } createAccount(); ...


3

Here is one of my deploy scripts. Feel free to modify it as needed. Code which deploys a smart contract | deploy.js const Web3 = require('web3'); const { interface, bytecode } = require('./compile'); const web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.56.103:8000")) const deploy = async () => { const accounts = await web3.eth....


3

Get the contract object via: const contract = await new web3.eth.Contract(JSON.parse(interface), smartContractAddress);


3

This is basically down to the interpretation of your input data as bytes or as a string. A good way to test this is using web3 in a browser (eg just visit the remix site and there's a console window you can use. This shows the following: > web3.utils.keccak256("...


2

In case anyone ever stumbles upon this problem this is the solution: the nonce has to be increased for every deployed contract web3.eth.getTransactionCount(senderAddress) .then(nonce => { web3.eth.personal.unlockAccount(senderAddress, password) .then(() => { for (let i = 0; i < amountOfContractsToBeSendOut; i++) {; ...


2

at method is deprecated since web3.js v1.0.x. Instead you can use this format: var myContract = new web3.eth.Contract(abiInterface, contractAddress);


2

Use node version manager(nvm) to install the latest stable node js version. https://github.com/creationix/nvm The most recent stable version is 10.15.1 After that, Run the same command to not see the error.


2

Try installing a newer version of web3, otherwise update node, try yarn and I guess other things, if you had docker you should be able to install.


2

For web3.js 1.0, I got it working like this: In head: <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.34/dist/web3.min.js"></script> Then get a reference to it: <script> var web3js = new Web3(new Web3.providers.HttpProvider('https://testnet-rpc.gochain.io')); </script> And use it like this: var contract = ...


2

Perhaps off-topic, as this is really a JS question... it returns { [Function: get] request: [Function: bound ] } That's because the call is asynchronous, so it's returning a Javascript Promise. See the Web3 documentation for an example of how to make the call correctly: web3.eth.getBlockNumber() .then(console.log); > 2744


2

You may notice in the comments, I was unable to work out what wasn't working for me, but not a fan of "it works, thanks" answers which don't help others. So I have put a working example up on gists for anyone who is looking for this. Just need to make some changes to be specific to your situation, but should be relatively straight forward. https://gist....


2

That's a Node question, not a Truffle question, but you can do this in two steps: Step 1 - create file common.js and initialize your common stuff in it, for example: module.exports.myVal = 42; module.exports.myFunc = function(x) {return x;}; Step 2 - import and use this file in your Truffle tests, for example: const common = require("./common.js"); ...


2

You're missing }); at the end. const ApprovalContracts = artifacts.require('../../contracts/ApprovalContracts.sol'); contract('ApprovalContracts', function (accounts) { it('initiates contract', async function() { const contract = await ApprovalContracts.deployed(); const approver = await contract.approver.call(); assert.equal(...


2

So one way to do it is with event. You can reaf more about it at here: https://solidity.readthedocs.io/en/v0.5.3/contracts.html#events. So basically you just have to emit an event with the value, address and then you listen to that event on backend server and then your javascript file will execute upon that event. You can use this web3: https://web3js....


2

You have two problems: web3.eth.getBalance() returns an promiEvent object, to obtain the expected value you need to await for it Javascript doesn't support large numbers, so values are wrapped in BN objects, and assert doesn't know how to compare those objects against numbers One solution is converting BN objects to strings to compare them. const balance =...


2

You can use the Ethers.js utils to pack the data how the v2 AbiEncoder would: https://docs.ethers.io/ethers.js/html/api-utils.html?highlight=packed#solidity Example from the docs: let result = utils.solidityKeccak256([ 'int8', 'bytes1', 'string' ], [ -1, '0x42', 'hello' ]); console.log(result); // '...


2

This is proxy contract, which means that it delegates actual work to another contract, probably to this one: 0x0882477e7895bdc5cea7cb1552ed914ab157fe56, which in turn is ERC-20 compliant. Proxy contract allows its administrator to change address of the contract actual work is delegated to, effectively changing smart contract logic. Proxy contracts like ...


2

There is an alternative method. You can download ganache from the below link $https://github.com/trufflesuite/ganache/releases/download/v1.2.2/ganache-1.2.2-x86_64.AppImage After it has downloaded execute the below command in terminal $cd Downloads $sudo chmod a+x ganache-1.2.2-x86_64.AppImage Now search for ganache and double click on it and press yes ...


2

Yes, you absolutely can! You will have to us the EthereumJS-tx package from NPM, you can get more information here: https://github.com/ethereumjs/ethereumjs-tx. It's as simple as: const EthereumTx = require('ethereumjs-tx').Transaction const privateKey = Buffer.from( 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex', ) const ...


1

Retracted ... just leaving this here for the comments thread.


1

Ethereum does not understand your password and cannot use it. Your password is only used within your client - it's typically used to encrypt the file which contains your private key. Password is therefore not directly linked to the private key in any way. So whenever you want to use your private key the process goes something like this (at least in Geth, ...


1

There are some projects that are researching in the area Parity bridge connecting two ethereum blockchains https://github.com/paritytech/parity-bridge. Polkadot A more complex interactions with heterogeneous blockchains https://polkadot.network/#whatisit. A bridge for a specific project https://github.com/Giveth/giveth-bridge But I don't know a general ...


1

Download Node.js and npm from https://nodejs.org/en/, and then install them. Run npm install web3.


1

web3.eth.getBlockNumber(function (err, blockNumber) { document.getElementById("status").innerHTML = blockNumber; });


1

I assume you are using Web3.js, which provides a library for just this use-case: Web3.js v0.2 - Big Number Web3.js v1.0 - BigNum Converting a number to the equivalent number with 18 additional zeros is as easy as calling a function: web3.utils.toWei('1', 'ether'); > "1000000000000000000"


1

This works: "data":contract.addBonus.getData(bonusType, target, year, month, day, token, bonus, bonusName, ineq),


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