Questions tagged [receive]
`receive` is a keyword that was introduced in Solidity 0.6.x that is used as a fallback function that is only able to receive ether.
31 questions
0
votes
2
answers
23
views
what exactly are the limitations of the require() function concerning my custom logic
I wrote some logic for a fundraising contract
function fund() public payable {
// myValue = myValue + 1;
require(msg.value.getConversionRate(s_priceFeed) >= MINIMUM_USD, "...
1
vote
1
answer
29
views
NFT Contract receiving NFTs from other, unrelated NFT Contracts
Imagine a contract A is deployed by Adress "Owner".
Then, an unrelated contract B sends NFTs to contract A's deployment address.
Is it possible for the Owner to do anything with contract B ...
0
votes
1
answer
16
views
Can a contract's receive function use part of the value as additional gas?
Since a contract's receive() can only rely on 2300 gas being available, is there any way to use part of the msg.value to top up the gas?
0
votes
1
answer
1k
views
HOW TO TRANSFER ERC1155 NFT TO ANOTHER WALLET
I Have A Ethereum ERC 1155 NFT in my Trust W. I want to send it to my MetaMask Wallet. Do I send this NfT to my MetaMask the same way as if I was sending a regular NFT?. Like normally sending a BNB ...
2
votes
1
answer
632
views
How can msg.sender call a payable function with set price from another contract?
hello everyone and happy '23.
I'm having issues sorting out the following system.
Contract TipWallet: receives tips with a takeTip() and updates the tip +1 every time it receives one.
Contract Tipper: ...
1
vote
1
answer
1k
views
Fallback and Receive functions in Solidity [duplicate]
I have a contract that needs to be able to receive Ether. The contract includes a receive function to receive Ether but I wonder if it's good practice to also have a fallback function in case someone ...
0
votes
1
answer
58
views
ParserError: Expected identifier but got 'receive'
I have two interfaces:
pragma solidity ^0.8.0;
interface EscrowParticipantI
{
function startEscrow(uint amount) external;
}
and
pragma solidity ^0.8.0;
interface EscrowServiceI {
receive() ...
0
votes
1
answer
199
views
What is the default gas limit for low-level calls?
I deployed the following contracts where one of the low level functions writes to a state variable and the other does not.
''' //SPDX-License-Identifier: MIT
pragma solidity <0.9.0;
...
0
votes
1
answer
183
views
Unable to deposit ether inside contract using receive function
Code is :
contract sendEther{
//to send ether, we need to deposit some ether first in this contract
//We can do it by declaring constructor as payable which enables us to deposit some ether ...
0
votes
1
answer
541
views
When to use a payable function vs. a receive function
This SO answer explains the differences between using a function marked with payable versus the contract implementing a receive function and then sending ETH directly to the contract: why contract ...
0
votes
1
answer
28
views
Connect Recipient Wallet - 'receive' function not defined
sorry to bother, trying to get an acknowledgment that my sender(msg.sender) address is sending to the receive() external payable. compiles fine, doesn't deploy correctly to show +1ETH in recipient ...
0
votes
1
answer
139
views
How to estimate gas of a receive method() in truffle
I know that if my contract has a name() method. I can go to the truffle console and try
contractInstance.name.estimateGas()
and this will give the estimate gas for that method.
but what if have a ...
1
vote
2
answers
87
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 ...
0
votes
0
answers
50
views
receive() & fallback() not receiving funds sent via .send()
I have this simple Caller Contract which is sending ether in 2 ways -
via .call() method // ether received in Called contract
via .send() method // ether not received in Called contract returns false ...
6
votes
2
answers
4k
views
why contract must have a receive()/fallback() to receive ether? isn't a payable function enough?
a contract just with a payable function can receive ether,
but why does the contract need to be add a receive()function to receive ether?
is there different between obtained ether via payable ...
2
votes
1
answer
823
views
How can we trigger `receive()` function in a smart contract when sender is a smart contract as well?
Let's say we have the following contract that is the receiver:
contract Receiver {
bool public received;
receive() external payable {
received = true;
}
}
How do we implement the ...
0
votes
1
answer
77
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 ...
0
votes
1
answer
575
views
Getting balance of received 1155 in receiver contract
I'm looking to build an airdropper that receives 1155 tokens and then runs a function to send them out to an array of addresses. However, I'm a little confused on two pieces
How to get the balance of ...
0
votes
1
answer
150
views
Automatically send Ether only when received?
How would I go about creating a smart contract that when the current wallet receives Eth. It would instantly be sent to a different specified address. I have experimented with the receive() function ...
0
votes
1
answer
716
views
Modifying receive function to take ether input instead of Wei
I am building a Shared Wallet contract as a project. As I have started working on the front end in react web app I have encountered the problem that javascript cannot store large numbers. I could not ...
0
votes
1
answer
43
views
Send ERC20 Tokens directly to contract address to trigger to function in contract
We are trying to bypass allow method and make the contract more UX friendly. And instead of first allowing contract to spend and after calling transferFrom method, we are thinking about just sending ...
0
votes
0
answers
13
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 &...
1
vote
0
answers
147
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 ...
0
votes
0
answers
68
views
receive() keyword
How can I execute methods in receive?
receive() external payable{
address _userAddress = msg.sender;
uint256 _amount = msg.value;
weth.deposit{value: msg.value}();
if(_amount>5){
...
1
vote
1
answer
518
views
Receiving ETH payments
As someone more familiar with bitcoin than ethereum I'd like to ask what would be the best way to accept ETH payments as a merchant? With bitcoin I can do following and my question is if it makes ...
1
vote
2
answers
430
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)
...
2
votes
1
answer
2k
views
How to trigger receive() fallback function | web3 geth
So Im pretty new to Solidity and I was looking into the receive and fallback functions and came across this very helpful post:
What is the receive keyword in solidity?
Then I read this:
The receive ...
0
votes
1
answer
74
views
Contract address payable issue
If i remove payable from:
then i get this error with my receive function. Not sure how to fix this. I have an erc20 token contract that has a receive function and this contract inherits from it, that'...
0
votes
0
answers
471
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, ...
0
votes
1
answer
491
views
Transfer money between contracts
I'm quite new at smart contracts/Solidity, which I'm learning for a postgraduate course.
In one of the assignments, we have to implement a little competitive game (something like the game of Seven ...
36
votes
1
answer
36k
views
What is the receive keyword in solidity?
Solidity has a receive keyword. What is it and how do I use it?