Hot answers tagged

5

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


4

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


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

Solidity's syntax has some similarities to JavaScript, and a large amount of tooling has been written in JavaScript. However, I would not say that knowledge of JavaScript is an absolute prerequisite. ethereum.org maintains a list of language specific resources that you may find useful: https://ethereum.org/developers/#language-specific-resources


3

I teach and develop courseware for B9lab. There is no absolute requirement for JavaScript knowledge and I would argue that similarities between Solidity and JavaScript are superficial. There is much to unlearn, in any case, because blockchain platforms are unlike any other form of software regardless of syntax. External to the blockchain there is always a ...


3

No, until today it was possible to connect Infura as ETH service provider by this endpoint mainnet.infura.io/PROJECT_SECRET But today smth went wrong and it trows an exception with message "project ID is required" Setting mainnet.infura.io/v3/PROJECT_ID as an endpoint throws "401 Unauthorized"


2

UPDATE: truffle-hd-wallet provider has been depreacted: https://www.npmjs.com/package/truffle-hdwallet-provider Instead use @truffle/hdwallet-provider: https://www.npmjs.com/package/@truffle/hdwallet-provider After this @truffle/hdwallet-provider will be successfully installed - then reference in required file as follows: var HDWalletProvider = require("...


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

For web3js > 1.0 you can use : myContract.deploy(options) const contract = new web3.eth.Contract(abi); contract.deploy({ data: code, }) .send({ from: "0x1234567890123456789012345678901234567891", gas: 1500000, gasPrice: '30000000000000' }).then(function(newContractInstance){ console.log(newContractInstance....


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


2

I am expecting that you already executed npm init at first. I assume you are using windows? I always develop blockchain related stuff on Ubuntu. Here is what you need to do on windows to set it up properly. Step 1: npm install -g --production windows-build-tools Step 2: npm install -g node-gyp Now it should work! If you still have a problem make sure ...


2

Try: const contract = await new web3.eth.Contract(JSON.parse(interface)) .deploy( { data:"0x"+bytecode} ) .send( { gas: '300000', gasPrice: 10, from:accounts[0]}); Otherwise please make sure that your accounts array includes actual values.


2

With web3.js v1.2.x, you can use function web3.eth.abi.encodeFunctionSignature: const selector = web3.eth.abi.encodeFunctionSignature({ type: "function", name: yourObj.funcName, inputs: yourObj.params.map(param => ({type: param})) }); Or simply: const selector = web3.eth.abi.encodeFunctionSignature("getSupplyRate(address,uint256,uint256)"); ...


2

Ok. With this code the parts were errors might occur are very limited. Make sure providerUrl has the correct value. I hope you filled contractAddress correctly. Abi is the bigger problem. Do a console.log of it. I would suggest a JSON.parse on the abi. This might fix the problem. EDIT: What is your web3 version? Make sure not to use an outdated one.


2

Your Bytecode isn't a hex number. Prepend a 0x. For example 0x606060405260018054600160a060020a031916... EDIT: Nevermind you already did that. Here is another try. Convert the string to hex. parseInt("0x6060604...", 16) Take note of the radix 16. Leave this value unchanged.


2

Ganache can be configured to mine new blocks on a specific time interval. With this setting enabled you are able to include multiple transactions in a single block. To enable this functionality in the GUI, access the settings by clicking the gear icon in the top right corner. Choose "Server" settings. From there you will be able to disable auto-mining and ...


2

Run it again. More generally, run it inside a try/catch block until success. For your specific error, it is possible that the node is not synchronized with your account's current nonce, so you may want to add this to your options object: nonce: await web3.eth.getTransactionCount(0xYourAccountAddress) Since you may also encounter other types of errors, I ...


2

Have you unlocked account1 on Infura? Of course, that's not possible (and you wouldn't want it to be either). This mode of operation is available only when you're using your own private node, so that others will not be able to exploit your account. And even then, it is not a recommend mode of operation, since anyone hacking your node will be able to ...


2

You can set the nonce with {nonce: <nonce>} but the bigger question is WHY? The nonce should be managed by the client and there are valid reasons to track it yourself. Have a look over here at "Candidate 3" that I would recommend most of the time. Concurrency patterns for account nonce However, this is not a valid design. intends to put multiple ...


2

Try to work with ganache-cli instead of ganache-gui. We faced similar issues with our integration tests - lots of transactions are very slow with the Ganache GUI (especially unter Windows the UI has update problems). The command line interface ganache-cli is much more stable and runs in terminal as well as in docker container. From the functional point of ...


2

You need to: Sign up with Infura.io Login into Infura.io Click CREATE NEW PROJECT button and enter project name Then in project details screen you will see your endpoint URL. Something like this: mainnet.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. This URL you should use in your code. You may also configure additional security settings for your ...


2

Here is a working js script example of your contract: var Web3 = require('web3') let abi = [ { "constant": true, "inputs": [], "name": "fname", "outputs": [ { "internalType": "string", "name": "", "type": "string" } ], "payable": false,...


1

Your update function is a payable function which mean you must send money to it. The call method doesn't support a way to send money so you must use send method with some eth for it to work: https://web3js.readthedocs.io/en/v1.2.4/web3-eth-contract.html#methods-mymethod-send Tldr: Use send with some value instead of call


1

You're missing () after myContractInstance.methods['0xc4e41b22'].


1

You should not think of Ethereum transactions in the same sense as regular messaging / transactions / background runs in the "traditional" world. Information like exact timestamps is really irrelevant in Ethereum. A miner picks up transactions for his block and the miner decides in which order the transactions will be executed inside the block. All that ...


1

About 1. for creating fresh addresses you can use keythereum or ethers.js. Take a look on both libraries and pick the one you prefer. About 2. and 3. To track the payments I see 2 options: You will be using nodejs so you can setup nodejs cronjob and check in block range ({fromBlock: X, toBlock: 'latest'}) the new transactions that sent ethers to your main ...


1

Since it is private is there a way to replace solidity with vanilla JS? You'd need to write a compiler that could compile JS to EVM bytecode, and I'm pretty sure no one has done that yet. The accepted answer to the following question might help explain the rationale behind developing a new smart contract languages, rather than use an existing language ...


1

Unless you have a single authority reorganizations are still possible in a PoA. The authority in turn has to sign and send the block on time to the rest of network. If the next authority fails to receive the block on time it has to produce a new block and propagate it to the network. Until the consensus is resolved some nodes might see different chains. In ...


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