8

TL;DR receive is a new keyword in Solidity 0.6.x that is used as a fallback function that is only able to receive ether. receive() external payable — for empty calldata (and any value) fallback() external payable — when no other function matches (not even the receive function). Optionally payable. Long Answer Solidity 0.6.x introduced the receive ...


6

Here's the simplest way: keccak256(bytes(a)) == keccak256(bytes(b)); Just use keccak256() while converting the string to bytes.


6

Updated 2020 Solidity 0.6.8 introduced min and max keywords that can now natively tell you the min and max of an expected type. From the release page: Implemented type(T).min and type(T).max for every integer type T that returns the smallest and largest value representable by the type. You can try it out with the following code. Note that the uint256 ...


6

Fixed-Point ABDK Math 64.64 binary scalar with 2^64 precision one of the more popular fixed-point libraries, it's been praised as being super efficient Exponential decimal scalar with 18 decimals developed by Compound.Finance Fixidity decimal scalar with arbitrary number of decimals slower than 64.64, but with a somewhat more palatable API DecimalMath ...


6

Right click on the error, and change workspace compiler seems work.


6

"Technological limits" is a quite broad term, but some other relevant limits are, for example: Maximum contract size of 24 kB (see in this article) Limited stack depth of 1024 (see deprecated Call Depth Attack) And most importantly, every computation requires gas, which is limited by your gas limit (see gas costs for EVM instructions) For a more ...


5

You can use HDWalletProvider to connect to a provider (infura or your local node) using a mnemonic phrase. In case you are using truffle, you can do it by seting you config to something like this: ... networks: { kovan: { provider: () => new HDWalletProvider(mnemonic, `https://kovan.infura.io/v3/${infuraKey}`), network_id: 3, ...


5

With respect to the ".value(...)" is deprecated. Use "{value: ...}" warning: You can use the following pattern to remove the warning: (bool success, ) = recipient.call{value:amt}(""); require(success, "Transfer failed."); solidity.readthedocs.io , solidity dotsyntax 0.7.0 => The following syntax is deprecated: ...


5

From the Solidity 0.8.0 Release Announcement about the exponentiation operator (**): We hope that we found a rather efficient implementation and would also appreciate your feedback about that! For many special cases, we actually implemented it using the exp opcode instead of our own implementation. More specifically, exponentiation operations that use a ...


5

There are 3 commons way to query the ethereum blockchain for now : The Ethereum dataset from Google BigQuery. You can retrieve various information such as basic information about transactions, smart contract function calls, token (erc20) transfers ... You can query this using SQL. For example, here is a query to get the top 10 biggest ethereum holder : ...


4

Uniswap seems to have found a neat solution for this issue. Surround a part of your function with brackets: { // scope for _token{0,1}, avoids stack too deep errors address _token0 = token0; address _token1 = token1; require(to != _token0 && to != _token1, 'UniswapV2: INVALID_TO'); if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out);...


4

Solidity doesn't support floating-point arithmetic. You'll need to represent e with a pair of an integer numerator and an integer denominator. For example: uint256 eN = 271828; uint256 eD = 100000; Then, you'll need to replace every plan for x * e in your code with x * eN / eD. In order to achieve maximum accuracy while reducing the number of erroneous ...


4

I think that'll do it. pragma solidity 0.6.1; contract TestNode { uint[] nodes; function createNode(uint data) public { delete nodes; // This should reset the length to zero nodes.push(data); } function pushNode(uint data) public { nodes.push(data); } function getNode() public view returns(uint[] memory) ...


4

You are missing the constructor call. Even if you don't want to change the original ERC721 constructor, you still need one in your contract. Therefore you get the error of declaring it 'an abstract' contract. Abstract contracts cannot be instantiated. constructor() ERC721("GameItem", "ITM") public { } is already enough. You can always check the docs to see ...


4

This contract is quite "old" (pragma solidity ^0.4.15;). The logic is actually taken from the solidity compiler. When targeting older versions of the evm it was not possible to send along all gas. The solidity code still exists even now: https://github.com/ethereum/solidity/blob/develop/libsolidity/codegen/ExpressionCompiler.cpp#L2343 Solidity changed this ...


4

The 'exploit' no longer applies to solc v0.6, since then the compiler generates an error when there's an ambiguous call. As the author says solc v0.5 uses C3 linearization to determine the order in which functions will be called. In the cited example the C3 linearization order is [Bank, MultiAdmin, TempAdmin, Admin]. When funct() is called the first ...


4

You need to add () to the opcode returndatasize. For 0.6.12, check the EVM Dialect to see inline assembly instruction syntax. Change this line: switch returndatasize Into: switch returndatasize()


4

The basic unit of work of the EVM, usually called a word, is 32 bytes. This means that for the EVM, no matter whether we want to express 1 or 2^150, it will take 32 bytes, or 256 bits, to do so. Everything costs gas in the EVM, including memory, so the fewer words the better. A bytes is similar to byte[], but it is packed tightly in calldata and memory What ...


4

I had the wrong compiled file selected in the remix "deploy" drop down bar -_- for some reason the default file is the highest one in the hierarchy


4

Ran into this myself as well. Are you using ethers.js with Buidler? The safeTransferFrom method is overloaded and generally with ethers.js the bare definition is the default method used. If you run console.log( Object.keys(token) ) you'll see the methods on the token and you'll likely see two definitions of safeTransferFrom. Pick the one you want to use then ...


4

A function selector is the first 4 bytes in the hash of the function's prototype. A function prototype is defined as the function's name and its argument types by order. It allows you, for example, to call a function without knowing its exact return-value type: bytes4 private constant FUNC_SELECTOR = bytes4(keccak256("someFunc(address,uint256)")); ...


4

EIP-1884 changed the cost of an SLOAD from 200 to 800, which explains why you are seeing exactly 600 more than expected. It looks like the yellow paper has not been updated to reflect this change. Edit: I have opened a PR on the yellow paper repository to resolve this issue.


4

You cannot directly negate the result of a modifier, but an alternative way to do this would be to create a function and call that inside two different modifiers, if you want to avoid code duplication. For example: contract Foo { function checkSomething () private pure returns (bool) { // Do something here return true; } modifier isSomething ...


4

No issue. It is economically, not technically constrained. You might say the market runs out of money before the EVM runs out of space. You can write as much data as you and your users can afford. Someone pays for the gas to do it. The insert, overwrite, and delete costs within a mapping are scale-invariant. There are some non-obvious, possible effects at ...


3

For Hardhat users, there is a nifty plugin called hardhat-contract-sizer: $ yarn add --dev hardhat-contract-sizer Load it in the Hardhat config file: require('hardhat-contract-sizer'); // OR import "hardhat-contract-sizer"; And finally run it: $ yarn run hardhat size-contracts


3

You can get data through an oracle that calls an API, as blockchains themselves can't call APIs Here is how to get data through a decentralized price feed. You can see a list of contract addresses and their price pair in the chainlink price feeds documentation. pragma solidity ^0.6.0; import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/...


3

You can also scope variables like this uint var1; { (uint varA, uint varB) = getVars(); var1 = varA + varB; } // now use var1 Inspired by Uniswap.


3

Explaining further what atc mentioned in their comment, Fixed vs variable length Memory arrays have fixed length, which means their length cannot be modified after it is initialized. Since push() appends a new element at the end of the array, it is not available for memory arrays. Storage arrays, on the other hand, can have variable length. Yet, they're ...


3

Here is an answer for web3.py version 5.1 Example: from web3 import Web3 from .utils import create_contract from .events import fetch_events uniswap_factory = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f' factory_abi_url = 'https://unpkg.com/@uniswap/v2-core@1.0.1/build/UniswapV2Factory.json' erc20_abi_url = 'https://unpkg.com/@uniswap/v2-core@1.0.1/build/...


3

enum Dir {UP, LEFT, DOWN, RIGHT} corresponds to uint8 values 0, 1, 2 and 3. This explains why passing a value greater than 3 should cause some form of error. That said, require(false condition) returns REVERT opcode, not INVALID opcode. The latter is typically the result of either one of the following: assert(x) where x evaluates to false arr[i], where i ...


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