Questions tagged [solidity-0.7.x]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
21 views

Malicious ERC20 blocking batch withdrawals of tokens (e.g. ERC777)

I was wondering whether the following attack vector is possible in practice. There's a batch transfer function that is intended to batch transfer the tokens owned by the contract. That function ...
Mila A's user avatar
  • 264
1 vote
1 answer
50 views

What does the tilde symbol mean in Solidity integer type casting in the example below?

function _approveTokenIfNeeded(address token, address spender) private { if (IERC20(token).allowance(address(this), spender) == 0) { IERC20(token).safeApprove(spender, uint256(~0));...
Mila A's user avatar
  • 264
0 votes
1 answer
28 views

local initialization

I was working in this solidity code. here is the code sample from my project interface customeInterface { function token0() external view returns (address); function token1() external view ...
Biruk Damte's user avatar
0 votes
1 answer
197 views

Truffle/Ganache Gas Limit Increase [duplicate]

I had posted on the GitHub Discussion as well. I have this massive smart contract and my goal is to study the scalability of the contract. The values work for smaller sizes. However, it fails at ...
Harish Karthikeyan's user avatar
0 votes
2 answers
455 views

Better way to retrieve the values of all public state variables of a Solidity contract

My solidity "0.7.0" contract pragma solidity ^0.7.0; contract DoubleEscrowTrade { uint256 private locked = 2; //2: unlocked, 1: locked. uint256 is gas efficient than bool uint256 ...
user938363's user avatar
0 votes
2 answers
218 views

why do not I get an division error when I put 5/2 with the use assignment operator

I just found that when I do 5/2 with assignment operator, it does not give any error immediately and just give the result as 2 instead of 2.5. Would you please let me know why it is ? // SPDX-License-...
DHC's user avatar
  • 313
0 votes
1 answer
527 views

How do I check for empty bytes array?

In 0.7.6 I want to check if a bytes array is equal to "" or not, but the compiler doesn't like bytes fingerprint = ""; if(fingerprint!=""){ // do something } How do I ...
antioi's user avatar
  • 61
0 votes
0 answers
28 views

How do i get the price of an erc20 token from solidity smart contract [duplicate]

I'm building a dapp, i'm trying to get the erc20 token price in usd from my smart contract how do i go about this? this is very necessary as smart contracts cannot read from outside networks. I don't ...
Benjamin's user avatar
1 vote
1 answer
861 views

How to store mapping with inline assembly?

I have a special needs, store the mapping with assembly code. thank you very for everyone who can response this question. for example: contract assemblyMappingTest{ mapping(address => uint) ...
Wei KeBei's user avatar
0 votes
1 answer
267 views

How do you interface with a lower version of solidity

I'm trying to create a contract (solidity version 0.7.6) that interacts with some arbitrary contract of a lower version (0.4.21). However, I have been trying to declare an interface in (0.7.6) but it ...
antioi's user avatar
  • 61
0 votes
1 answer
251 views

why do i keep getting these error messages on remix IDE on compilation?

ALERT: Transaction Error. Exception thrown in contract code. I have tried all i could // SPDX-License-Identifier: MIT pragma solidity >=0.7.0 <0.9.0; interface IERC20Token { function transfer(...
Abbracx's user avatar
  • 11
1 vote
1 answer
224 views

call method in compiler 0.8

how can i change this for older compiler versions like 0.4.24? (bool success, ) = transaction.to.call{value: transaction.value}(transaction.data); and if you have time please explain to me the call ...
ali's user avatar
  • 41
0 votes
1 answer
500 views

How to send an amount of ether from the smart contract to an address and save any information along with the transaction (in the TX DATA) (solidity)

I need to send a certain quality of ether from the smart contract to an address, but the problem is that I need that along with that transaction I need information to be recorded in the blockchain for ...
Lara Trindade's user avatar
0 votes
1 answer
203 views

Factory pattern for multiple contracts inheriting from same abstract contract exceeds size

I have a base abstract contract which is inherited by 3 other contracts (all having the same interface). I am trying to use a factory contract to conditionally create instances of the derived ...
kautuk's user avatar
  • 1
0 votes
1 answer
696 views

How to use OpenZepplin hooks to cancel transfer if condition is not met?

I am experimenting with OpenZepplin Hooks to modify ERC20 transfer functions in this way contract IToken is ERC20 { .... function _beforeTokenTransfer(address from, address to, uint256 amount) ...
Flood Gravemind's user avatar
3 votes
3 answers
2k views

How to initialize and assign value to constant in constructor?

I have the following code and want to initialize a constant in constructor. import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract IToken is ERC20 { uint256 private ...
Flood Gravemind's user avatar
2 votes
2 answers
541 views

Can I write a function to edit an enum?

I have an enum with certain predefined data. If at a later date, I have to add or push in more choices , can I edit the enum using some function ? enum ActionChoices { GoLeft, GoRight, GoStraight, ...
Ashish kumar's user avatar
4 votes
1 answer
4k views

Unary operator minus (-) cannot be applied to type uint256

While trying to compile the mulDiv function part of the uniswap-v3-core code base, I got the following error: Unary operator - cannot be applied to type uint256 This is the line that causes the ...
Paul Razvan Berg's user avatar
1 vote
1 answer
948 views

Remix Solidity Smart Contract Stuck On Compiling State

The 1inch Smart Contract is unable to compile in Remix as it appears to be stuck in the Solidity compiling phase. Expected Create a new 1inch_38211317.sol smart contract file in Remix. Compile the ...
AdamHurwitz's user avatar
0 votes
1 answer
644 views

How can I test my purchase function on the truffle with chai?

I'm trying to test my token buying function but I encounter an error, o facilitate understanding I will show the code "Error: Returned error: VM Exception while processing transaction: revert&...
walter calegari's user avatar
0 votes
1 answer
37 views

Stack too deep error [duplicate]

Not sure what the best approach is to get around this. New to solidity. I've read the complicated 'answers' to this that suggest using structs, arrays, etc. but I can't figure out how to address this. ...
Ash's user avatar
  • 1
0 votes
1 answer
218 views

Mapping keys optimization in Solidity

I've looked through all answers here but still have the question for the latest version of Solidity. Perhaps, there exist new libraries Is it possible to optimize this mapping(address => uint) ...
Dmitry Dyachkov's user avatar
3 votes
1 answer
3k views

SLOAD costs 800 gas - how is it possible?

I've got a very simple contract. It narrows down and measures cost of loading a storage variable: pragma solidity ^0.7.6; contract Bench { uint256 public data; function increment() ...
CodeSandwich's user avatar
0 votes
1 answer
127 views

Ethereum unimplemented feature

I am trying to compile this code: contract C { struct s { string chan; string content; } s[] x = new s[](0); } And it lands me with a confusing compiler error: ...
pitust's user avatar
  • 3
1 vote
0 answers
303 views

Making function calls exclusive per block

I have the requirement that in my smart contract certain functions cannot be called, if another function already has been called inside the same contract during the same transaction. Imagine I have ...
Daniel Gretzke's user avatar
0 votes
2 answers
2k views

does the gasleft function return the total gas left for the transaction or the gas left for the function call

If a function is using the gasleft() function and is called by another smart contract, does it return the total gas left for the transaction or just the gas left passed to the function via the message ...
Daniel Gretzke's user avatar
0 votes
0 answers
35 views

override keyword usecase + what it does [duplicate]

function burn(uint tokens) override external returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); _totalSupply = _totalSupply.sub(tokens); emit ...
Lucus's user avatar
  • 107
0 votes
0 answers
32 views

Issuing 1-1 eth for token problem

pragma solidity 0.6.6; // import "./XYZToken.sol"; contract Vault { mapping(address => uint256) balanceOf; mapping(address => bool) hasDepositedEther; mapping(...
Lucus's user avatar
  • 107
0 votes
1 answer
206 views

Transfer funds to inherited smart contracts [closed]

How would I make this work - the balanceOf[Pool, System + Cube] doesn't seem to work ;-; // SPDX-License-Identifier: GPLv2 pragma solidity ^0.7.0; import "./Pool.sol"; import "./Cube....
Lucus's user avatar
  • 107
2 votes
1 answer
1k views

TypeError: Type string calldata slice is not implicitly convertible to expected type string memory

I want to slice a string and save it to a memory or storage variable. Is this possible? function test(string calldata _input) external{ string memory something = _input[1:3]; } I am ...
Felix_Maduakor's user avatar
1 vote
1 answer
1k views

Using inherited constructor in Solidity >=0.5.0

I want to use a contract inherit from another contract and use the parent constructor after using another commands in inherited constructor. So I wrote: pragma solidity ^0.5.10; contract A { ...
Alireza Zojaji's user avatar
0 votes
1 answer
158 views

"out of gas" when trying to send back ETH from a contract to tx.origin

(UPDATED) The contract should have more than enough ETH. I deploy the contract with 0.1 ETH: https://git.io/JUBdy const consumerExample = await ConsumerExampleFactory.deploy(process.env....
Markus Kottländer's user avatar