New answers tagged

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

The tricky part is that Erc20 tokens (and any tokens, for that matter) are not explicitly transfered when you issue a token transfer. Only account balances are updated in the token contract. So tokens are never included in transactions like Ether is. They are moved around by just asking the token contract to reduce balance from one account (address) and ...


1

This is how your contract should look like if you want to cover 0.6.x standard. However you should never fully trust any solitions here and always double check the logic you copy from here and make sure everything is working as it should be. pragma solidity ^0.6.0; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ ...


1

nested hell Yup. This is circular: struct B { B[] as; } B contains arrays of B? The dynamic array of a struct inside a struct pushes the limits of what the compiler can handle. You would have to construct a memory instance of the struct and use the push method, which isn't present and then copy the works into storage. As a general suggestion, ...


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


1

It is not possible in solidity for a function to return a variable of type mapping. The default getter of a public struct variable will not return dynamic data types like mapping or dynamic array. To access data from dynamic field inside an struct you have to implement your own getter. function getTaskFreelancer(uint256 taskId, uint256 idx) public view ...


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

Apart comments on your code, that time you are trying to measure is always zero, I.e. it is not measurable in terms of CPU effort See: Solidity: Is there any way to calculate the elapsed time for smart contract?


0

It sounds like you've got some things mixed up. Let's start with a more abstract description of things. Consider the following two conceptual ways for you to hold money: You have N dollars in your wallet The bank has a record indicating that you own N dollars On the blockchain, whenever we say that user k has N tokens of type XXX, we mean that the ...


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


1

See the example below Warning from Remix: Experimental features are turned on. Do not use experimental features on live deployments. pragma solidity ^0.5.12; // Enable the ABI v2 Coder pragma experimental ABIEncoderV2; contract AbiTwoTest { struct Item { string str; uint num; bool bol; } struct Arg { Item[]...


0

So taking a look at the events on etherscan, it looks like Approval events have been submitted to approve the transfer of 2 tokens from 0x62f28320f688a7a4e0021c55d7ffd1acd770a133 (your wallet?) to 0x813870feba76f27ec1afcf79432e065a4839f7ab (your contract) However I wrote a small contract to check the balances and allowances in the ERC20 contract you are ...


0

You can use assembly language to access the byte code of the smart contract that you've just deployed within your smart contract. See the simplified example below for details. Using remix, you can deploy the factory, and then call register and it will emit an event with the byte code of the smart contract you just deployed. Based on your example - you could ...


0

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


0

A web3 call means you're just reading from a local node, not mutating the state of the blockchain, see What is the difference between a transaction and a call? As you noticed, avoiding call and just calling the method on the web3 contract instance will mutate the contract state. This is because you are sending a transaction. In web3, sending a transaction ...


1

I see you modified the question after several valid/correct answers: Question is: how to invoke GenNextID like a regular function, that is: call to this function mutates internal state it returns result returned from the contract's code YOU DON'T You either mutate the state and get a receipt, or you get a response but you don't mutate the ...


1

The code below compiles with ^0.5.16. There were a few updates needed. 1 - constant is no longer used. You need to use either view or pure more info here I made all view because they read the state. 2 - I needed to set the visibility for each of the functions. I made all public. More options here 3 - payIn is a function that sends money to the contract, ...


0

Here you go. I changed .send() to .transfer(), because transfer throws on failure while send is returning false on failure and you are not checking it anywhere. Had to setup visibility for all the functions and replace constant with view, because constant got deprecated in the latest versions. Next time just place your code into https://remix.ethereum.org/ ...


1

We solved this by having a one time init function. For full source, see ThingFactory.sol and Thing.sol. Basically, what you do is have this one time init function on your target contract (in the example, it would be Thing.) Then your factory contract calls the init function directly after creating the clone. The ...


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


0

Yes. Just to amplify and clarify, this is an easily-misunderstood issue. private does not imply, in any way, any assurance of confidentiality whatsoever. Some further explanation might help. As you know, Ethereum nodes process every transaction. In order to do that, they need access to the contract state, including the values of private variables. If ...


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

I realize you're new to this. Some of your phrasing suggests possible confusion that could lead to this error. trying to deploy a contract via Remix Deploy to what? deployed on Metamask to where? I will break that down a little. We have to deal with code, compilers, chains and tools. Remix, as you know, is an IDE, has the JavaScript VM which is ...


1

The problem is related to the ABI JSON produced by the compiler and how the tools use it to determine if a function is view or pure. As you can see in the docs: The fields constant and payable are deprecated and will be removed in the future. Instead, the stateMutability field can be used to determine the same properties. Now, see how different are ...


0

When you want two contracts to be closely related I create both before running the tests contract('MyContract', async () => { let token let faucet // This function will execute once before all the tests before(async () => { token = await MockToken.new() faucet = await Faucet.new(token.address) }) it('Faucet', ...


0

it's an old trend i hope you have solution, but if someone has the same question let me say that you are missing assign values to owner here: address public owner; // contract owner you need do it:  address public owner = msg.sender; you can do it in the same line or into a constructor :) and delete this function that you created: /// Set owner ...


0

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


1

Your question indicates: Total cost in wei units = 67123160000000000 Gas price in wei units = 20000000000 This implies that the amount of gas required is 67123160000000000 / 20000000000 = 3356158. This amount of gas should be identical on every network (assuming that you're using the same compiler in order to generate the byte-code which you are deploying)...


0

Found some examples here. And for the above example, the hello contract should be something like: function say() public constant returns (string memory output) { bytes32 out; assembly { let memPtr := mload(0x20) mstore(memPtr, 0x20) let success := call(gas, 10, 0x0, memPtr, 0x20, memPtr, 0x20) ...


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

The Type includes the functions and a deployment address, once its instantiated. So, instances will have methods that correspond to the contract functions. For example, a function might take an address for a KittyContract and then use it for something. Since your example stored exactly one, let us say that's part of the constructor. constructor(address k) ...


0

This error means that Truffle cannot find a network entry for the current network ID in the build artifact file. Whenever a truffle migration is done, the build artifact JSON (typically under build) is updated to include a mapping of network ID to contract address. Thus whenever you reset your test blockchain, e.g. restart ganache-cli, you need to re-...


0

Here is an example of how you can achieve this: IERC20 public daiInstance; uint256 public totalSupply; mapping(address => uint256) public balances; constructor(IERC20 _daiInstance) public { daiInstance = _daiInstance; } function buyXXX(uint256 daiAmount) external { uint256 xxxAmount = toXXX(daiAmount); bool success = daiInstance....


0

I deployed your CrowdSale contract in Remix IDE using the Javascript VM with no issues. creation of Crowdsale pending... [vm]from:0xca3...a733cto:Crowdsale.(constructor)value:0 wei data:0x608...77b3alogs:0hash:0x650...40b38 status 0x1 Transaction mined and execution succeed transaction hash ...


1

It declares a storage variable of type KittyInterface. You can also define a storage variable to be a contract type and then use it in your contract instance. An example is given in the solidity docs: https://solidity.readthedocs.io/en/v0.6.1/contracts.html#creating-contracts contract OwnedToken { // `TokenCreator` is a contract type that is defined ...


0

This is solved as Mikko explained in the comment.


0

The perhaps confusingly-named interfaces mapping, mapping(address => mapping(bytes32 => address)): maps account address (whether for EOA or contract) to another mapping the second mapping is from (essentially) interface names to addresses of contracts implementing the interfaces So for example, you could have a deployed contract that is able to send ...


0

The if statement below is failing in the transfer function of the LoanToken.sol contract if (_balances[msg.sender] >= amount && amount > 0) { This is failing because this function is being called from the problem2_bank.sol contract. For this reason msg.sender = the problem2_bank.sol contract's address rather than the address that was funded ...


Top 50 recent answers are included