Questions tagged [fallback-function]

Questions dealing with the Solidity fallback function

Filter by
Sorted by
Tagged with
1 vote
2 answers
26 views

How to send back the value sent to the fallback?

Is there a way to get and keep the value sent to the fallback/receive functions? Let's say, I want to send back Ethers that sent to my contract. Okay, existence of fallback function is enough to deal ...
user avatar
  • 13
0 votes
0 answers
21 views

Decode number of tokens and token contract address from msg.data (ERC-20)

I have a smart contract with just a fallback function and some logic. I want users to send their tokens directly to the smart contract to do some smart contract logic on receive. I've implemented ...
user avatar
0 votes
2 answers
160 views

address.call{}(abi.encodeWithSignature()) in solidity returns boolean and what other parameters?

I learned from this documentation https://docs.soliditylang.org/en/v0.8.15/contracts.html and this discussion How to use address.call{}() in solidity about abi.encodeWithSignature() . I have question ...
user avatar
  • 105
0 votes
1 answer
126 views

delegate call from a fallback function using msg.data doesn't work

Please look into the following 3 contracts: // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.7; contract implementationProxy { uint public a; uint public b; address owner; ...
user avatar
0 votes
1 answer
90 views

fallback not executing

I have a test project with proxy pattern (fallback/delegate call). The purpose is to have upgradeable contracts. Here is the proxy contract: // SPDX-License-Identifier: MIT pragma solidity 0.8.13; ...
user avatar
  • 105
2 votes
2 answers
433 views

Can ERC-20 token transfers have re-entrancy?

I understand that re-entrance attack can happened when you send ETH, because of fallback() function. But in ERC20 transfer there is no call for fallback, so I wonder if there's a way to make re-...
user avatar
  • 21
0 votes
0 answers
18 views

Modify msg.data

Is it possible to modify msg.data by assigning a new value to it and forwarding it to the next function call? For example: Proxy.sol fallback() external payable virtual { _fallback(); } ...
user avatar
  • 327
0 votes
0 answers
33 views

Unable to understand solidity code

I was confused how this smart contract is sending requested loan amount back to this smart contract again by calling flashLoan. Reference this challange of Damn VUlnerable HERE // SPDX-License-...
user avatar
0 votes
0 answers
33 views

What is evm_increaseTime function and can we use it for real world blockchain or only for testing smart contracts?

I have been going through evm_increaseTime and evm_mine functions but not able to detail it properly and having doubts with following questions: What is evm_increaseTime function? Where do we use ...
user avatar
1 vote
0 answers
38 views

how to unit test fallback function using solidity by passing data

fallback() external payable { bytes calldata data = msg.data; bytes memory lendId =bytes(data[msg.data.length-32:]); //last parameter must be lendingId uint256 _lendingId = uint256(abi....
user avatar
  • 11
0 votes
1 answer
38 views

Events in Chained Fallback Function Cause VirtualMachineError

I’m working on an upgradeable contract that uses fallback functions with inline assembly delegatecall and call calls (using calldatacopy and returndatacopy) to route internal and external function ...
user avatar
  • 126
1 vote
1 answer
56 views

How to check which fallback handler is set for a Gnosis Safe

I am using a 1.3 Gnosis Safe. I want to check what fallback handler is set. I find the function that can set it: function internalSetFallbackHandler(address handler) internal { bytes32 slot = ...
user avatar
  • 7,226
0 votes
1 answer
19 views

very important interface need help

the balance not change from another contract pragma solidity ^0.8.10; interface ICounter { function balanceOf(address owner) external view returns (uint); function transfer(address to, uint ...
user avatar
  • 1
0 votes
1 answer
53 views

How to interact with my first defi smart contract in remix?

I found this tuto online : https://cryptomarketpool.com/create-a-defi-bank-that-pays-interest-yield-farm/ and i deployed my token and my smart contract on testnet via remix. The issue is that i am a ...
user avatar
  • 103
1 vote
0 answers
36 views

What the this keyword means?

im doing the ethernaut course. what does this mean ? I know what for exemple address(this)means, it s the address of the smart contract but like what does it means when the this is alone like this?
user avatar
  • 13
0 votes
1 answer
29 views

Contract does not accept eth sent from another contract

Hi I try to send ETH from Sender contract to Receiver contract by calling sendPayment function. But I get an error. I know that the issue is the require statement in the fallback function because ...
user avatar
0 votes
1 answer
199 views

Transferring a value into a fallback function of a contract

I'm trying to figure out what happens when you send a value to a contract. If the destination address (to) is a contract, then the EVM will execute the contract and will attempt to call the function ...
user avatar
  • 617
0 votes
1 answer
109 views

State variable not updated after DelegateCall

I deployed two contracts 'WalletLibrary' and 'Wallet': most of the functions in Wallet delegateCall() the functions from WalletLibrary. I want to recreate an Attack, where I call the initWallet() ...
user avatar
0 votes
1 answer
20 views

Sending balance to contract fails

I'm playing ethernaut, the king of the hill level. I made a practice target contract and an attacking contract. I want to send value to the attacking contract (this works) then I want to send the ...
user avatar
0 votes
0 answers
233 views

How the fallback and receive functions in version 8 differ from fallback function in version 5 of Solidity?

I found that in version 8, we explicitly use the keyword fallback for fallback function and there is a receive function also. Consider the following code: receive() external payable { ... } fallback() ...
user avatar
  • 1,233
0 votes
0 answers
12 views

Struck with receive() and fallback() error. TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address" [duplicate]

I am new to solidity, learning smart contract development. I got stuck while I was learning about the fallback function. This function throws an error saying "TypeError: "send" and &...
user avatar
0 votes
0 answers
26 views

How does one trigger a fallback if it wasn't automatically triggered? "def _fallback() payable: # default function revert"

so I have a friend who sent funds to a contact address which did not have a way of accepting it and I can also see it contains in the contract "def _fallback() payable: # default function revert&...
user avatar
1 vote
0 answers
91 views

Contract does not have fallback nor receive functions

In what circumstances a test can fail with the error "Contract does not have fallback nor receive functions" ? My contract already contains both a fallback and a receive function: event ...
user avatar
2 votes
1 answer
843 views

web3 estimateGas() from fallback function

When I sign and send raw transactions with web3 in javascipt , to call a method from Smart Contract, I always pass the transaction gas variable after getting it with estimateGas function, from Smart ...
user avatar
  • 705
2 votes
1 answer
573 views

Why does solidity need a fallback function? [duplicate]

I understand when the fallback function is called, but why is it needed at all? It leaves the way open for a possible reentrancy attack. It is called when a function of a contract is called that isn't ...
user avatar
  • 21
0 votes
1 answer
205 views

Sending ether to a contract without data throws an error

I'm trying to deploy a smart contract that allows users to buy tokens that can be used to pay fees on its platform. In case someone is going to send ETH directly to the contract address without ...
user avatar
  • 101
0 votes
1 answer
359 views

Receive keyword in solidity

I was making a smart contract in which I wanted to send and receive ether. My code: contract coin_transfer_to { function() public payable { } function get_balance() public returns (uint) ...
user avatar
0 votes
2 answers
796 views

Truffle Console: Sending Ether to a contract using fallback function

I have the following contract: pragma solidity ^0.5.8; contract Victim { address owner; constructor() public{ owner = msg.sender; } function deposit() payable public {} } If ...
user avatar
  • 1,233
0 votes
1 answer
92 views

Reflect Base contract's update in another contract

I have wanted to know what concept is it called when we want two contracts which are deployed on the Network, reflect the transaction and updates in another contract. for example: contract Base{ ...
user avatar
1 vote
2 answers
962 views

What happens if there is no fallback function in solidity?

Here is the short definition about fallback function in solidity: Solidity fallback function does not have any arguments, has external visibility and does not return anything. What happens if there ...
user avatar
0 votes
1 answer
246 views

Way to fetch function name in fallback function with Solidity

I am writing a fallback function this way: fallback() external { (param1, param2) = abi.decode(msg.data[4:], (uint256, uint256)); } I know this is not a good practice but let's suppose i ...
user avatar
  • 1,099
3 votes
1 answer
361 views

Using selfdestruct in constructor

What's the purpose of such a call to this stub? contract Sacrifice { constructor(address payable _recipient) payable { selfdestruct(_recipient); } } Usage: if (_token == address(0)) { ...
user avatar
0 votes
1 answer
371 views

Why isn't my initial sendEther function not recognized as a receive ether function, am getting the error shown below [closed]

Error: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function. Here is my code: // SPDX-License-Identifier: MIT pragma solidity >=0....
user avatar
0 votes
0 answers
73 views

amount of gas used in receive and fallback functions in truffle tests

I have a contract that is written in solidity ^0.6.4 and has a simple implementation of reverting funds when someone directly transfers some eth or calls an unhandled function. Now it appears to be ...
user avatar
  • 1
2 votes
1 answer
342 views

What is the gas limit for a fallback function called when the method does not exist?

According to the docs a non matching function identifier will trigger the fallback function. So what happens if someone calls my contract with "thisMethodDoesntExist()", would the fallback ...
user avatar
1 vote
1 answer
46 views

Do gas refunds apply in a fallback function? What is the limit for non matching function identifiers?

I know that a fallback function called with a .transfer only has gas limit of 2300. What happens if the fallback function deletes some storage variables in the fallback function? Would the fallback ...
user avatar
0 votes
1 answer
2k views

How should 'fallback' function be defined if we transact using 'call' method? [duplicate]

i came to know that 'call' method is better for transacting, since all gas is transferred and could withstand reentrancy attack.. but how should we define fallback function for 'call' method? using ...
user avatar
  • 3
0 votes
2 answers
279 views

My fallback function can not get msg.value from a sent transaction

There is a mapping in my code as mapping(address => uint) private Payment;. This mapping is used to see who send some ether and how much the sent value is. Its key is an address that stores ...
user avatar
  • 375
0 votes
2 answers
150 views

Implement tokenfallback on an existing ERC20 Token

I have an ERC20 token which is already deployed on the mainnet. I want to make a contract which accepts this token from users and pays dividends in Ethereum stored already inside the contract. In my ...
user avatar
  • 3
2 votes
1 answer
214 views

Why would someone have a fallback function for ^0.6.0?

A receive function allows a contract to accept eth via a send() or transfer(). As someone thought it was a good idea to have both a receive and a fallback function, I was curious what sort of scenario ...
user avatar
0 votes
0 answers
317 views

Failing to send() 1 wei from one contract to another

The following code is supposed to send 1 wei from the current contract to a newly created contract. The recipient contract gets created successfully and the sending contract has a positive balance, ...
user avatar
  • 190
0 votes
0 answers
140 views

Compile error. Fallback function error

I use pragma 0.6.2. I am trying copile in truffle code which contain this lines: fallback() external payable{} I an getting error: The payable fallback function is defined here. fallback() external ...
user avatar
  • 11
1 vote
1 answer
666 views

method like fallback function for ERC20 tokens?

I want to write a contract that uses USDT (Tether) for payment. How can I use the ERC20 token as an ERC777 token, for example: Use a fallback function that executes when we receive USDT token. Or use ...
user avatar
0 votes
0 answers
73 views

Truffle console: Exception instead of transaction

I am running the tutorial at: Medium Just Dev pragma solidity ^0.5.0; import './Victim.sol'; contract Attacker{ Victim public v; uint public count; event LogFallback(uint c, uint ...
user avatar
  • 1,233
27 votes
1 answer
22k views

What is the receive keyword in solidity?

Solidity has a receive keyword. What is it and how do I use it?
user avatar
1 vote
1 answer
474 views

Forward all function calls and arguments to another contract

I want to build a truly upgradable contract. I want the child contract to only implement state and then forward all functional requests to a main implementation contract. So the scheme should look ...
user avatar
  • 1,142
1 vote
3 answers
732 views

Solidity 0.6.1 Receive Fallback Forwarder reverts due to insufficient gas

I am playing around with Solidity 0.6.1 and trying to build a simple funds forwarder. So ETH is sent to the contract and it sends the funds to another address. I deployed it to Ropsten. But every ...
user avatar
1 vote
1 answer
751 views

What's wrong with an 'empty' fallback function?

Contract A interacts with another contract B, which generally interacts with humans (ie, externally owned accounts). Thus when contract B sends ETH to contract A, contract A needs a fallback function ...
user avatar
0 votes
1 answer
164 views

Upgradable contract proxy pattern: Get the invoked method name in the fallback function

I have a proxy smart contract and I would like to get the name of the called method in the fallback function. Is there a way? For example, if I call the function getName() (stored in the logic ...
user avatar
  • 157
1 vote
2 answers
861 views

How to test a custom fallback function using web3.js?

I am trying to implement a proxy pattern. I have a proxy contract and a lottery contract, and I would like the proxy contract to delegate calls to the lottery contract. To test that the function ...
user avatar
  • 181