Questions tagged [solidity-0.7.x]
The solidity-0.7.x tag has no usage guidance.
32
questions
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 ...
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));...
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 ...
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 ...
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 ...
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-...
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 ...
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 ...
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) ...
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 ...
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(...
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 ...
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 ...
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 ...
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)
...
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 ...
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, ...
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 ...
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 ...
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&...
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. ...
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) ...
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() ...
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:
...
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 ...
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 ...
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 ...
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(...
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....
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 ...
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 {
...
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....