Hot answers tagged

6

When view function is executed on-chain, i.e. within mined transaction, it consumes gas, and this protects node from infinite loop. When executed off-chain via Web3 API, caller is still able to specify gas limit for the execution, see documentation. If gas limit is not specified, it is up to particular implementation how to protect from such things, ...


6

Prior to Solidity v0.4.21: contract ContractName { function ContractName(...) public { ... } ... } Solidity v0.4.21 onward: contract ContractName { constructor(...) public { ... } ... } The reason: In the older version, if you renamed the contract but forgot to rename the constructor, the latter would turn into a ...


4

you have to configure a new network to connect to via Metamask open Metamask go to settings > network > add network ! and there add your new network if it's a local node in RPC URL put: http://127.0.0.1:7545 and chose a name for it and save then go on the top menu of Metamask and choose your newly created network to be the host of the communication and that'...


3

In ERC-721, each token is completely unique and non-interchangeable with other tokens. The key features of both are: ERC-20: For money and money-like tokens. ERC-721: For things and thing-like tokens. According to the nature of these tokens, nowadays most of the games are using ERC-721 tokens e.g. Cryptokitties because kitties are unique and non-...


3

You should avoid iterating the list of permitted accounts. It's an expensive approach that doesn't scale and it has a lot of moving parts. Consider instead using a mapping. This is a namespace where all the uninitialized indexes return false, 0, empty, depending on type. For example: mapping(address => bool) public whitelist; returns true or false for ...


3

I assume that you are connecting your DApp with the blockchain using the browser web3 instance, which is provided by metamask. The alternative is to use Infure or your own node and change the web3 provider, then metamask will not pop-up and you can implement your own logic when someone click on a button to send a transaction, but then it is more complicated.


2

Invalid opcode can be the result of either one of the following runtime operations: assert of an expression which evaluates to false array[i] where i >= array.length In your code, only the second option appears viable. It is viable in the expression userNotes[msg.sender][_noteId]. So the error must be the result of _noteId >= userNotes[msg.sender]....


2

Your transactions to the contract show that you aren't including any tx data, meaning you aren't calling createChildContract.


2

tokenReward.transferFrom() us called from Campaign. From the perspective of tokenReward, msg.sender is Campaign. Hope it helps.


2

Try this way: web3.eth.getAccounts( (error, accounts) => { ... } )


2

You can use this website to create a Keccak256 or Keccack512 checksum of a file: Source code can be found on GitHub.


2

You need to use ABIEncoderV2: pragma experimental ABIEncoderV2; contract Foo { string [] private strings; function addString (string memory str) public { strings.push (str); } function getStrings () public view returns (string [] memory) { return strings; } } See documentation for details.


2

Actually there is not support from solidity for returning an array of strings as described here: Return dynamic array of string You can fix it adopting this workaround described here: Deserialize a string


2

On first look, this is an anti-pattern. In summary, it looks like confusing authentication with privilege and internal organization. The pattern goes against the natural organization of the platform and will likely lead to non-trivial difficulties. The natural way. You will presumably need authentication and access control. The good news is that all ...


2

Maybe you are looking for something like OpenZeppelin contracts (implementations of tested libraries/contracts to build contracts).


2

All your migrations run from the beginning. Using ganache blockchain (for this example), you can check this information at the bottom of your contract's .json files. Before --reset: "networks": { "5777": { "events": {}, "links": {}, "address": "0x2429A2d4d4eE68C33a08e0490f5E3daf9d3329Ef", "transactionHash": "...


2

You are making a fundamental mistake which makes it all seem much harder than it really is. Instead of an array, your should use a mapping(address => bool), let's call it whitelisted. Add people in the whitelist like this: whitelisted[_address] = true; then in your modifier, you can simply do this: require(whitelisted[_address]);


2

I recommend that you look at the OpenZeppelin guide on Access Control, specifically the section on Role-Based Access Control as using Roles from OpenZeppelin appear to meet your needs. https://docs.openzeppelin.org/v2.3.0/access-control For questions on use, you can also ask in the community forum https://forum.zeppelin.solutions/


2

A dApp consists of two different parts: the blockchain part and the more traditional www interface part. The blockchain part has no idea about cookies, it's deterministic and can't communicate directly with the external world. All information has to come and go through nodes. The more traditional www interface part is almost just like any other website. So ...


2

Function approve is not constant (neither pure nor view). You should therefore execute it using send instead of call.


2

Why A transaction may succeed or fail depending on when/where it was mined. The initial state matters and that is only knowable when the transaction exists in unambiguous transaction order. Consider getting paid on the same day rent is due and your landlord has a post-dated check. The order of events, the transaction order, may be the determining factor (...


2

Since solidity 0.5 keccak256 is expecting bytes as input and you are passing an uint. You can use abi.encodePacked to convert an arbitrary input to bytes. keccak256(abi.encodePacked( (rw() / (10**20) ) % (10**12) ) )


2

Yes you need to use send. Here is the code: const result = await contract.methods.stop() .send( { gas: '1500000', gasPrice: `30000000000000`, from:accounts[0]}); This code needs to be placed in an async function as it uses the async/await pattern! Regarding your question with the from address. This is a state changing transaction. Therefore, ...


2

Constructor functions should not have a name. Just this will do fine as a constructor: constructor() public { totalSupply = 10000; }


2

An invalid opcode exception typically implies either one of the following two scenarios: An assert(cond) statement with cond == false An array[i] expression with i >= array.length You don't have any assert statements in your code, so you should start by looking into every x[y] statement. However, some of those statements in your code are with x being a ...


1

This is a generic answer - I'm not going to try to implement any of the games you mentioned :) The Ethereum virtual machine is Turing-complete (kind of) so you can write anything you want with it - all the algorithms are possible. You just need some language which gets converted into the bytecode which the EVM understand - Solidity is the most common one. ...


1

The most essential distinction between Hyperledger and Ethereum is the intent they are designed for. Ethereum runs the Smart Contracts on the EVM for applications that are attributed to being decentralized and are for mass consumption. On the other hand, Hyperledger leverages blockchain technology for business. It is designed to support pluggable ...


1

Keeping the app in the blockchain doesn't cost anything. The following is true at least for Ethereum (no idea about Hyperledger): You pay for development You pay for deployment (gas costs) You pay for using the app (gas costs) - except for read-only operations. Depending on the implementation typically anyone can interact with the app on the blockchain so ...


1

You can run your dapp without ganache, truffle, npm e.t.c. you can host your frontend to github pages. write a contract on online remix Ide,deploy it it to testnetwork. Get address and ABI, connect it to frontend and deploy frontend on GitHub pages and access dapp from website with metamask.


1

As per the first question you can send value like this: LotteryPot newContract = (new LotteryPot).value(amount)({ _potName: potName, _duration: duration, _minStake: minStake, _potType: potType }); Secondly, for sending the msg.sender you can change the signature as: constructor ( string memory _potName, uint _duration, uint _minStake, ...


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