A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

New answers tagged

0

Based on The failing function call is the set Two suspects: Suspect ONE require( keccak256(abi.encodePacked(storedData[_index])) == keccak256(abi.encodePacked('')) ); If I read that correctly, the requirement is the storedData == '', so possibly that isn't the case. Suspect TWO require(owner == msg.sender); Check owner() and make sure that is your ...


1

Azure provides an RPC security layer that enforces access control to the network. In order to provide authentication to your RPC interface you can use basic authentication, certificate based authentication or you can link to your identity provider. After you are part of the network (rpc auth passe) you have Quorum state authorization layer (what is called ...


0

You can use this function (tested with web3.js v1.2.1): const ABI = [{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]; async function send(web3, contractAddress, destAddress, ...


3

You are correct - anyone with the address & ABI can call a public contract. The only way to prevent this is to have code within the contract that checks for calls from authorized addresses. If a private key is lost then the contract would need to be updated to replace that authorized address. I suggest you take a look at Quorum's smart contract based ...


0

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"


0

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


1

You can also obtain it programmatically: const keythereum = require("keythereum"); console.log(keythereum.recover(yourPassword, yourJsonObject).toString("hex"));


1

The error message is misleading. You can safely disregard it since you aren't calling the constructor or sending funds. It's a lot of code to wade through so this won't be very specific. You say this seems to be the issue: request.recipient.transfer(request.value); The most likely cause is the contract doesn't have sufficient funds to make that happen. ...


0

Found my answer. On metamask, I can export private key of selected account Click on the threedots Click on Account details Click on export private key. It now ask you a password: it's the Metamask password. It's specific to metamask. Then it will show you the private key. Keep it absolutely private, do not share, do not save on cloud!


0

Why not do something like: OraclizeContract.deployed().then(function(instance, fromAddressX) { console.log("Initializing"); instance.deposit({from: fromAddressX, gas: 3000000, .... This way you would pass the fromAddress you want as an input argument to your function. document.getElementById("fromAddress1").addEventListener(...


1

You need to sign the transaction with the private key of the account, and then send it to the node. For example (tested with Web3.js v1.2.1): async function send(web3, privateKey, gasPrice, contract, receiverAddress, numOfCoins) { const account = web3.eth.accounts.privateKeyToAccount(privateKey).address; const transaction = contract.methods....


0

What's weird is the code I'm using in my Node.js file is the exact same code I've been using in my regular client-side JS files (which are embedded into my HTML files) - which work perfectly well. You clearly have two different versions of Web3.js installed: Your client-side environment relies on Web3.js v0.x. Your NodeJS environment probably relies on ...


1

Here is the general scheme: transactionHash is fired right after the transaction is sent (almost immediately) receipt is fired when the transaction receipt is available error is fired if an error occurs at any point during this process confirmation is fired for every confirmation up to the 12th confirmation Note that the more confirmations you wait for, ...


0

I think, $ npm show web3 this command shows the version of web3 globally installed on your system. let web3js = require("web3") let web3 = new web3js(new web3js.providers.HttpProvider('http://localhost:8545')); console.log("VERSION", web3.version) this shows the locally installed version of web3 in your current project.


0

theContract.events.yourEventName is neccesary. const theContract = new web3.eth.Contract(abi, contractAddress, { from: fromAddress, gasPrice: 200000000 }); theContract.events.saleTXReceivedEvent((error, event) => { console.log(event); });


0

So my mapping was not working fine, I was using metamask and web3, I worked for 2 days but couldn't find anything But finally, I was able to fix it by adding add ethereum.enable() before calling ethereum.send MetaMask introduced a Privacy Mode that requires dapps to ask permission to view users’ accounts Here is my code window.addEventListener('load', ...


1

Executed this: const Web3 = require("web3"); const web3 = new Web3("http://localhost:7545"); const dataHash = "0x3c6819779a3c0a163d93e2e1e1168fb5ab424217555132ea356d491002c84e7f"; const user1Addr = "0x72f27f62998bc1a2929a72bf753b6a335abd46c0"; const user1PvtKey = "0xc73c6b7ad8e821a303871e8a63f8a53c9b6b0cf3977becd94032f3ff7c3055c1"; async function ...


0

First of all, found too many bugs in the contract. i would suggest you use remix to solve your bugs first. 'throw' is deprecated use require. Second. It is best that when you contract.transfer just transfer the balances from payer1 and player2 and let player 2 be notified of the deposit and he can now withdraw the money from contract. This is best practice ...


0

I hope that this will answer your question: walletAddress = '0x62f28320f688A7A4e0021c55d7ffD1acd770A133' → walletAddress[0] = '0'. And when you call contract2.balanceOf(walletAddress[0]), web3 most likely converts that '0' into the zero address 0x0000000000000000000000000000000000000000', whose balance is apparently 0. Side note: You're obviously using ...


0

You have hard-coded an amount of 1 (one wei!!!) when calling function transfer: contract.transfer(fromAddress2, 1, ... After transferring that amount, the difference will not show up when you view the balances on metamask, because the display-resolution of this application is 1 ether (10^18 wei). And of course, because you've hard-coded that amount, your ...


0

EDITED Take a look at my code here, I'm able to request the sellPrice, buyPrice and totalSupply methods from your smart contract.


0

I'm able to execute balanceOf and sell methods like this: const contract = web3.eth.contract(abi).at(address); window.addEventListener('load', async function() { // Wait for loading completion to avoid race conditions with web3 injection timing. var web3; var globalState = {}; console.log(web3, 'web3'); if(window.ethereum) { ...


0

Just for for you: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="account-address"></div&...


0

First get all the accounts: const accounts = await web3.eth.getAccounts(); Then get balance of the first one, for example: const balance = await web3.eth.getBalance(accounts[0]); BTW: I used "await" in the example above, thus your function has to be an async one, e.g. async function getUserBalance() { const accounts = await web3.eth.getAccounts(); ...


1

There is event accountsChanged provided by latest MetaMask version and you can use it like this: if(window.ethereum) { window.ethereum.on('accountsChanged', function () { web3.eth.getAccounts(function(error, accounts) { document.getElementById('account-address').innerHTML = accounts; }); }); }


0

First of all, web3.eth.getBalance(account) doesn't get you the token balance of an account, but the ether balance of an account. In order to get the token balance of an account, you need to call token.methods.balanceOf(account). Second, whether it's the token balance or the ether balance that you want, both functions above return a promise which you need ...


0

Edit your code like this: window.addEventListener('load', async() = > { // Wait for loading completion to avoid race conditions with web3 injection timing. if(window.ethereum) { const web3 = new Web3(window.ethereum); try { // Request account access if needed await window.ethereum.enable(); ...


0

Change line: window.addEventListener('load', () => { To: window.addEventListener('load', async () => {


0

First of all your website must be allowed to connect MetaMask. This can be achieved by adding the website url in MetaMask -> Settings -> Connections. If you want dynamic solution for your users your website need to run this code whenever your it's loaded so your users don't have to deal manual whitelisting your website: if(window.ethereum) { await ...


0

Let's clarify some concepts first: A (client) node is used to connect to the blockchain. A node is the only possible way to communicate with the blockchain. You can either run your own node (quite much effort) or use a ready node service provider which offers you access to their nodes (such as Infura). Metamask is a browser extension which facilitates ...


0

This is more of a javascript problem not solidity or web3. require() does not exist in the browser/client-side JavaScript. What you can do is follow the example here and then attach the bundled javascript file to your html.


0

From the code I see you're using web3 0.2.x correct? I looked at your contract code and got a bit confused what is method betOnTeam doing, I didn't see ETH transferring inside of it. Anyway if you are using MetaMask this is the way to fire transaction: function ready(){ document.getElementById("bet").addEventListener("submit", function(e){ e....


0

Below is an example using react, ethers, and metamask to interact with an erc20 contract on ropesten. When the page loads it triggers the following transaction request in MetaMask to transfer the erc20 tokens: Also here is an example using web3 MetaMask Transaction Request React / JS code import React, { useState, useEffect } from 'react'; import abi ...


0

Looks like you have some syntax errors (also that test is checking the total supply, not setting it), please try the following: contract('TtdmToken', (accounts) => { it('Checks whether or not the total supply is equal to 1,000,000', () => TtdmToken.deployed() .then(tokenInstance => tokenInstance.totalSupply()) .then((totalSupply) =>...


0

window.addEventListener('load', () => { // Wait for loading completion to avoid race conditions with web3 injection timing. if (window.ethereum) { const web3 = new Web3(window.ethereum); try { // Request account access if needed await window.ethereum.enable(); // Acccounts now exposed return web3; } catch (error) { ...


0

But if a value is stored in an event, is there an efficient way to retrieve its value from a web3.js script (which is not running all the time and so cannot effectively subscribe to events)? There is a stateless (almost) pattern to consider. pragma solidity 0.5.16; contract BreadCrumbs { uint public prevChange; event LogChange(string arg1, ...


0

It worked for me following this code.. function approve() external payable{ require(msg.sender == approver); address(uint160(receiver)).transfer(address(this).balance); }


0

http://jsbeautifier.org/ can be used to format the code first; then you should edit the resulting file with a deep variable and function name substitution (using a text editor), changing the obfuscated names with something meaningful. You, in practice, have to reverse engineer the code by hands. Other resources do exist in internet, but none can do the ...


0

Ok, I see @rob-hitchens-b9lab has answered the question beautifully while I was busy ;), so I'll give a short, cookbook answer of the steps I don't know what you're using but most people are familiar with Remix, so here are the steps in Remix: In the "Solidity Compiler" tab, create and compile an Erc20token.sol file : interface Erc20Token { function ...


1

A @Chan-Ho says, there is a transferFrom() in the buy function, and you said you didn't approve() first, so that is the first problem. This looks like the Token contract - AGI: erc20 = TOKEN(address(0x8eb24319393716668d768dcec29356ae9cffe285)); You have to call the approve() function there to "authorize" the snet contract to pull some tokens from your ...


1

Your test uses a beforeEach() to set up new, blank contract to play with. That's an agreeable thing so no test is dependent on any other. The function uses a modulo to pick a row and then forges ahead to work, but if there are players, because enter() wasn't called first, then the modulo will be zero and it will try to access row 0 in players and that ...


0

Not sure if you posted the full app.js, but your app.js is missing a circular bracket ) right at the end.


1

No no no. The accepted answer above is incorrect, and the fact that you've accepted it means that not many users will even read your question (let alone try to answer it). The integer value of 1000000000000000000 is indeed larger than Number.MAX_SAFE_INTEGER, and you should therefore use "1000000000000000000" or "1e18". But that's not what the error ...


0

Looks like there's a bug report already filed for this. It will be fixed in version 1.2.2 (current version is 1.2.1). Assuming this ever worked, you can try using a prior version <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.2.1/dist/web3.min.js"></script> where you replace 1.2.1 with the version that didn't have this issue.


1

consider adding the following function to your smart contract: function getSpentLimit(address a, address b) public view returns (uint256) { return spentLimit[a][b]; } then you can call this function in your smart contract using web3.js using a and b as parameters


1

Try this: const crypto = require("crypto"); const rand128 = "0x" + crypto.randomBytes(16).toString("hex");


4

There is a util that can create a "cryptographically strong pseudo-random HEX strings from a given byte size." You could then convert this to a number. web3.utils.randomHex(size) --> documentation Per the github web3js documentation the library frozeman/random is used to generate randomness


2

You use the transaction's hash to obtain the transaction's receipt, if you made a single call to createCourt you have a single event in the receipt. Another option is to accept an random input parameter and use that as id.


0

You can add second parameter to your event: event CourtCreated(address indexed _address, uint256 _id); And later on execute the event in your methods like this: emit CourtCreated(msg.sender, _id); Now with the keyword indexed before _address parameter with web3.js you can filter the events by the address. You can check which events are executed by you ...


0

Token transfers are not actually transfers of value at all. Only Ether transfers explicitly transfer (and contain) value. So a transaction transfers Ether if and only if its value field is non-zero. Detecting a token transfer is much more tricky. A token transfer is simply calling a function in a token contract. So first you need to know whether the ...


Top 50 recent answers are included