Questions tagged [payable]

The payable modifier in Solidity can be used to make smart contract functions able to receive either, or to make Ether transfers to address variables possible.

Filter by
Sorted by
Tagged with
0 votes
1 answer
25 views

Unable to transfer eth into contract in hardhat

I am working on some ERC20 tokens in which user have to send it to get tokens, i am getting some error while running it!! i am stuck at the const txHash = await addr1.sendTransaction({ to: ...
user avatar
  • 13
0 votes
0 answers
9 views

UUPS Upgradeable Smart Contracts - How to Fund Them with Ether Upon Initialization

When I deploy a non-upgradeable contract, I fund it with Ether in this manner: const MyContractFactory = await ethers.getContractFactory("MyContract"); const myContract = <MyContract>...
user avatar
0 votes
1 answer
16 views

Need to specify the amount with payable(msg.sender)?

I am working through Mastering Ethereum and have been building their first example Faucet Contract. I recognize that a lot of their syntax is out of date, and written in ^0.4.19. I've been writing it ...
user avatar
  • 1
0 votes
1 answer
24 views

How do I test extra parameters in Remix?

I tried to use Remix to test a Smart Contract: /******************************************************************** * Make bids with ETH or an ERC20 Token specified by the NFT seller.* * Additionally,...
user avatar
0 votes
0 answers
21 views

How to Call a payable function I am getting error={"code":-32603,"message":"Internal JSON-RPC error.","data":{"code":3,"message":"execution reverted"}

I am trying to call buy function which is a payable function using metamask signer method. I am getting error for sending incorrect ether value. Here I have set the price as 1 which is 0x01 in hex ...
user avatar
  • 325
0 votes
2 answers
58 views

Send msg.value to another address immediately

Is it possible to implement a payable function and transfer msg.value to another address immediately? function purchase() payable public { //transfer msg.value } I'm thinking this wouldn't work ...
user avatar
0 votes
0 answers
41 views

Swapping/Exchanging an NFT on Solidity

To summarise, this contract aims at swapping an NFTs for another NFT. The two NFTs are separate external contracts, and the first token contract has approved the second contract's address to transfer ...
user avatar
0 votes
1 answer
30 views

Payable function transaction failing

Please see the following code: // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.1; contract Crowdfund { uint fundLimit = 3 ether; bool contractOpen = true; function donate() ...
user avatar
0 votes
1 answer
37 views

Why are we using payable modifiers in both the ERC20 transferFrom and approve functions?

Why are we using payable modifiers in the ERC20 functions below? function transferFrom(address _from, address _to, uint256 _tokenId) external **payable** { require (zombieToOwner[_tokenId] == msg....
user avatar
0 votes
2 answers
28 views

why I am not getting balance of contract?

when I call the getbal() of contract "Account" it shows 0 balance but when I call createacc() of contract "accountfactory" with value=30, accountfactory's balance becomes 9.but ...
user avatar
  • 1
0 votes
0 answers
22 views

Why i cant initialise a variabel with msg.sender

why i can't initialise a variable address payable public owner=msg.sender; but i have to do this instead address payable public owner; constructor() payable { owner = payable(msg.sender); }
user avatar
0 votes
1 answer
25 views

How to send from a contract to a personal wallet

// SPDX-License_Identifier: MIT pragma solidity >=0.6.6 <0.9.0; //2.56 //import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; import "hardhat/console.sol&...
user avatar
0 votes
2 answers
155 views

"The called function should be payable if you send value and the value you send should be less than your current balance." error for non-transfer func

This is my first post on this stack exchange site and it comes after a couple of hours of banging my head against this error's wall. In short, I am currently going through a solidity course and one of ...
user avatar
0 votes
1 answer
13 views

Error while calling a function that is not payable

I was trying to execute the below contract and calling the function approveOperator but it says, "The called function should be payable if you send value and the value you send should be less ...
user avatar
0 votes
3 answers
169 views

How to send ether from a smart contract address to another address?

I have a contract that I can deposit ethers by using a fallback function. The question is, I want to send the ethers INSIDE THIS smart contract to another random address. I am not asking to send ...
user avatar
0 votes
2 answers
110 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 ...
user avatar
0 votes
1 answer
51 views

payments ( pre set value) in solidity

I am developing a movie renting smart contract where the owner can add new movies, clients can search movies and pay for the movies they select. Adding and searching is working to my liking. The ...
user avatar
0 votes
0 answers
14 views

How should I write tx to swap ETH for sETH in curve pool?

I try to write script to swap ETH/sETH. but the result is always revert. const amountIn = new hre.ethers.utils.parseEther("1"); const amountMin = await curveContract.get_dy(0, 1, amountIn); ...
user avatar
  • 1
0 votes
1 answer
56 views

Problem in withdraw() function in Auction contract, !payable is used still its able to refund the amount of the lower bidders when we click withdraw

In Withdraw Function, !payable condition is given, but payable condition not given, still when we click withdraw, then we will get our money back if we dont have the highest bid pragma solidity ^0.8.4;...
user avatar
0 votes
3 answers
278 views

Add a price for minting an NFT

I attempting to implement an NFT minter into my application, but want to set prices for minting an NFT. I'm using a smart contract template I found but havent been able to figure out how to set prices....
user avatar
  • 1
0 votes
0 answers
59 views

What is Payable field in Etherscan

If I mention a function as payable in solidity then there comes an extra field in Etherscan for the same function if I deploy the contract in Etherscan. It has a placeholder with payableAmount (ether)....
user avatar
  • 123
0 votes
0 answers
15 views

I can't implement the transfer function that calls the A contract through the B contract. who can help me

I want to call the function of contract A in my contract B. I call the balanceOf function to display the balance normally, but when I call the transfer function, it does display Note: The called ...
user avatar
0 votes
3 answers
394 views

How to call a payable function and pay from the contract balance?

First, this is not a duplicate question of these ones: How can you call a payable function in another contract with arguments and send funds? Calling and funding a payable function from existing ...
user avatar
0 votes
2 answers
98 views

How to check if an address is payable

I'm working on a contract that will pay token owners. I'd like to check if an address is payable before sending. I know I can cast to payable like so: payable(address); How can I check if the address ...
user avatar
  • 212
0 votes
1 answer
85 views

When does a payable function "claim" or "take" the sent ETH?

For a smart contract function to receive Ether, it is marked payable. Is there a specific point in the execution of the code where the sent value is "claimed" or "taken" from the ...
user avatar
  • 69
2 votes
1 answer
45 views

How to tell if an address is capable of receiving transfers

If I receive ether in a payable function on a my smart contract, is there any way to tell if the msg.sender is also capable of receiving ether short of sending a few wei back to the sender to see if ...
user avatar
  • 457
0 votes
1 answer
136 views

Creating a smart contract that only accepts a specific ERC20 token [duplicate]

Currently building a smart contract that will basically receive money from users and users can withdraw what they've put into. I want the money held by the smart contract to be only USDC (+ USDT maybe,...
user avatar
  • 26
0 votes
2 answers
28 views

Payable function not called when receiving ETH from mining

I have a contract which is in charge of dispatching ETH to a set of registered address. When I transfer ETH to it, the functionality works well, however when the ETH comes from a miner the ETH are not ...
user avatar
0 votes
1 answer
34 views

Why does my mint function throw an insufficent amount error?

I'm testing a smart contract on REMIX, everything works but the mint function provided throws an insufficient amount error even though I have enough ether in my account. It seems like theirs no ether ...
user avatar
  • 175
0 votes
1 answer
437 views

Using payable functions in the remix ide

I created a simple solidity contract in the remix ide. I cannot figure out how to test the payable functions I created. here is an example of a payable function: function pay() payable { } here is a ...
user avatar
1 vote
1 answer
36 views

Forwarding Ether from one contract to another

I am currently try to write two smart contracts. Here is the first one: // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract Token { mapping(address => uint) ...
user avatar
  • 495
0 votes
1 answer
143 views

Function can send ETH without using payable?

I understand that a function must be declared as payable in order to send ETH to some address. I am trying this piece of code using Solidity 0.7.1 pragma solidity ^0.7.1; contract SendMoney { uint ...
user avatar
  • 105
0 votes
1 answer
39 views

Ways to invoke contract methods

I'm just starting learning development on Ethereum. So far I created a couple of local projects using truffle / web3js / react-native. Right now I started solving exercises on https://ethernaut....
user avatar
  • 115
0 votes
1 answer
81 views

How do I pay functions in remix?

I am making an NFT vending machine. Here's the code: // SPDX-License-Identifier: MIT pragma solidity ^ 0.8.10; contract VendingMachine { address payable internal vendingAdmin; struct item { ...
user avatar
  • 21
-1 votes
1 answer
34 views

How to restrict a function call only to the owner of a private key of a public key in a parameter (many users)?

Let's say, there's something like a lottery. And there's a function in a smart contract that allows ANY user among users to check whether he's won something or not. If he has, it'll allocate the coins ...
user avatar
1 vote
1 answer
532 views

How to access the price nft asset is being sold for in your NFT contract?

I have a unique case in which I want to implement an NFT contract that prevents users from selling/transferring NFT tokens below a specific ether price. Opensea uses wyvern protocol for NFT order ...
user avatar
0 votes
3 answers
401 views

How to tell if an address is a contract or just an address in solidity

My solidity contract allows users to earn interest on their token holding. I want to prevent contracts which hold my token from earning interest. This will stop the pancakeswap router or any other ...
user avatar
  • 123
1 vote
1 answer
30 views

Converting to address payable not working

address payable constant public pillowInc = address(uint160(0x4B38016118FDE970e2371740F849840aEc745c7B)); address payable constant public pillowInc = 0x4B38016118FDE970e2371740F849840aEc745c7B; ...
user avatar
  • 41
1 vote
1 answer
506 views

How to web3 "encodeFunctionCall" a payable function?

I want to encode a call for mint() payable with a msg.value of 8 ETH. My code: web3.eth.abi.encodeFunctionCall({ type: 'function', name: 'mint', payable: true, value: web3.utils.toWei(&...
user avatar
0 votes
0 answers
36 views

Payable function that calls another contract out of gas

I have a smart contract that implements a payable interface for a mint function. The contract is pretty simple: pragma solidity ^0.4.5; contract PayableMinter { address dc; function ...
user avatar
  • 89
0 votes
1 answer
154 views

ParserError: Expected primary expression indicating "payable"

this is the solidity version: // SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.9.0; this is the function that throws error: function withdraw(uint withdrawAmount) external { ...
user avatar
  • 506
0 votes
1 answer
257 views

Sending ether to a payable function in Solidity doesn't decrease the sender's Ether in Ganache

I have the following smart contract: pragma solidity ^0.8.0; import "./IERC20.sol"; import "./MyCoinSupply.sol"; contract MyCoinDEX { IERC20 public token; event Bought(...
user avatar
0 votes
1 answer
15 views

Error: function must be payable but it does not contain transaction

I'm new to blockchain and solidity. I've acquired a problem that seems strange to me. Look the code below pragma solidity >=0.7.0 <0.9.0; contract Dealership { address owner; ...
user avatar
0 votes
1 answer
569 views

How to transfer Ether from a smart contract to an account?

I wrote a very simple smart contract. The goal is to: transfer some Ether from an account A to the smart-contract and then from the smart-contract to another account B. Here is the contract: pragma ...
user avatar
0 votes
1 answer
15 views

I'm trying to deploy a Wallet onto the Blockchain AND deposit some Ether in it AT THE SAME time...... ie using the Remix DEPLOY button

I feel this should be VERY SIMPLE. So code the Constructor to require an Amount and therefore that Amount will be then taken from the Metamask Wallet at the same time as the GasFees are paid for the ...
user avatar
0 votes
1 answer
557 views

Solidity send value of payable function to owner: "Send and transfer are only available for objects of type 'address payable', not address"

Simple test/use case, there is a payable function that should send money directly to the owner. I get the error as in the title. Code: address private owner; constructor() { owner = ...
user avatar
  • 138
2 votes
3 answers
1k views

What’s the difference between fallback() and receive() and between payable vs transfer?

I saw there are two type of function available, but I don't understand the difference. If another contract send to my contract for example $100 BUSD, how do I know when I received them? I saw there ...
user avatar
  • 25
0 votes
1 answer
125 views

Using payable custom tokem

I'm creating an NFT game and I have a big question about payable. Below I'm putting my code that I'm invoking a new Hero. function invokeRandomHero() public payable { require(msg.value == 0.001 ...
user avatar
  • 121
0 votes
0 answers
139 views

The called function should be payable but I don't want it to be payable

I already checked the internet for possible solution but none could help me. I'm using Solidity ^0.8.7 Below is a function to update a ranking of addresses and is triggered by function transfer(). ...
user avatar
0 votes
0 answers
82 views

How to insert a payable function in an NFT contract

I am creating a contract and I'll like to get paid for my NFT's in an ERC20 token other than Ether. Can someone recommend an implementation? I tried this implementation: function getNft(string memory ...
user avatar

1
2 3 4 5