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
1answer
21 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 ...
1
vote
1answer
23 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) ...
0
votes
1answer
14 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 ...
0
votes
1answer
22 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....
0
votes
1answer
16 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 { ...
0
votes
1answer
24 views

Using transfer function always exceeds balance, or allowance!

I've been struggling with transfer function, where approval is not needed on ERC20 tokens where the caller is msg.sender as it's a public function, but I'm always getting same error.. Indeed I am on ...
-1
votes
1answer
19 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 ...
0
votes
1answer
129 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 ...
0
votes
2answers
31 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 ...
1
vote
1answer
10 views

Converting to address payable not working

address payable constant public pillowInc = address(uint160(0x4B38016118FDE970e2371740F849840aEc745c7B)); address payable constant public pillowInc = 0x4B38016118FDE970e2371740F849840aEc745c7B; ...
0
votes
1answer
101 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(&...
0
votes
0answers
24 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 ...
0
votes
1answer
41 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 { ...
0
votes
1answer
67 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(...
0
votes
1answer
14 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; ...
0
votes
1answer
97 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 ...
0
votes
1answer
13 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 ...
0
votes
1answer
148 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 = ...
1
vote
2answers
268 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 ...
0
votes
1answer
30 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 ...
0
votes
0answers
70 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(). ...
0
votes
0answers
57 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 ...
0
votes
0answers
13 views

set value is not working

i have develop a hotel booking smartcontract, it checks the vacancy and price for a guest to book the hotel. i have set the amount such way so that it can be change with time, but the set function is ...
0
votes
0answers
44 views

Can't use payable function of other contract

I wrote a contract which I will deposit eth in and this contract should mint on another contract, but it does not seem to work. Why? Here is my code: pragma solidity ^0.8.0; //SPDX-License-Identifier: ...
0
votes
1answer
185 views

Can't Call Payable Function from Web3

I am trying to call a public payable function from my smart contract (^0.8.0) in a ropsten testnet function purchaseCardPack() public payable { require(msg.value == cardPackFee, "...
0
votes
1answer
215 views

Is it possible to achieve receive eth and mint nft in the same contract?

recently I'm build some ERC721 nft contract. I know that smart contract can receive ETH, so my question is that is it possible to write a payable function, and upon receive some ETH from someone, the ...
0
votes
1answer
40 views

payable function not working the way I expect it to work

When sending some ether to the Proxy contract (payable method addBalance) and forwarding it to Token contract I expect the ether balance of Token contract to increase with the ether amount. However ...
0
votes
1answer
29 views

Transfer from contract address to sender

I am coding a crowdfunding contract where senders have two options. First, payIn which invokes a transfer to the contract's address. Second, withdraw which invokes a transfer from the contract's ...
0
votes
0answers
32 views

Buying ERC1155 token with payable

The constructor for ERC1155 token standard looks like this: constructor() public ERC1155("https://game.example/api/item/{id}.json") {} However, the example given on OpenZeppellin mints all ...
0
votes
0answers
222 views

Error: Encoding arguments invalid address

I'm trying to write a simple smart contract which uses uniswap to exchange eth for tokens, and then tokens back for eth When I deploy my contract in remix I get an error: creation of EzSwap errored: ...
0
votes
1answer
986 views

Can a payable function in a solidity contract only receive the native token or coin of the chain?

Can a payable function in a solidity contract only receive the native 'protocol' token or coin of the chain? So for example, a payable function on an ERC-721 contract can only receive ether? The same ...
1
vote
1answer
410 views

Ethers js deploy contract with balance, payable constructor

I have a smart contract with a payable constructor. I'm trying to figure out the syntax with ethers js how I can deploy the smart contract and send an initial balance with the deployment. const ...
0
votes
1answer
23 views

Transferring to contract from another contract - payable error when transferring

I have a contract (the factory) that deploys other contracts. These contracts behave like bonds where users can set an amount in the factory, deploy the bond and then others can subscribe to the bonds....
1
vote
1answer
205 views

ParserError: Expected primary expression. when using payable

I have the following code: function payout() public payable { uint ordersLength = orders.length; uint totalRaised = 0; for (uint i = 0; i < ordersLength; i++)...
0
votes
0answers
15 views

TypeError: address payable best practice v0.8.6

I'm getting TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address" for items[_upc].consumerId.transfer(...
0
votes
1answer
474 views

Where to pass the value at while using msg.value?

I had been using remix IDE for a long time but recently switched to using Truffle. Everything else was fine until I had to build a function for payment. In remix IDE, there is a box provided, labelled ...
0
votes
1answer
252 views

error type address is not implicitly convertible to expected type address payable

I get the following error type address is not implicitly convertible to expected type address payable on the withdraw function. pragma solidity ^0.8.1; contract sendMoneyExamples{ uint public ...
1
vote
1answer
835 views

how are we sending funds on polygon through contract

I know it sounds like a basic question (it should be), despite that I could not find any clear reference to that in polygon's (Matic) docs on how does payable(address).call works pragma solidity ^0.7....
0
votes
1answer
50 views

How does Solidity handle multiple payables in one function?

While I was experimenting with Solidity, this question popped in my head and I've been struggling to figure it out ever since. To test things, I wrote this simple contract: contract test{ uint256 ...
0
votes
0answers
19 views

Gas estimation fail only when sending eth to contract?

I have a payable function that works fine when calling without any eth, but if I try to call it with eth it gives me a gas estimation fail. I have another function that is payable and works fine when ...
0
votes
1answer
35 views

The called function should be payable if you send value and the value you send should be less than your balance

This is one of my parent contract (child factory contract) functions that creates a child contract. The function should be provided with 3 arguments function breed(uint _number, uint _amount, ...
0
votes
1answer
17 views

What would happen if I remove + from the line number 6?

pragma solidity ^0.8.1; contract SendMoneyExample{ uint public balanceRecived; function recivedMoney()public payable{ balanceRecived+=msg.value; } function getBalance()public ...
0
votes
1answer
26 views

Does anyone know how to fix this address not payable error on my //Perform Sell section?

pragma solidity >=0.5.0; import "./Token.sol"; contract EthSwap { string public name = "CutiSwap Instant Exchange"; Token public token; uint public rate = 100; event ...
0
votes
1answer
322 views

Require a specific amount of Ether inside the payable function

I have a payble function that has some logic. I want that logic to be triggered only if the received amount is equal to the amount specified when the contract was created. Solidity v0.7.6 receive() ...
0
votes
1answer
33 views

How to make a smart contract which pays out only if a service is performed?

Hello I am new to the world of solidity. I am trying to create a smart contract with the following conditions: a customer wants to buy a service/product from a retailer (me). the price of my service (...
0
votes
0answers
37 views

How to send ethers to specific address based on solidity contract but not web3py?

I have written a solidity code, running it on Remix and I use ganache and web3py library to interact with it. My code is something like this: contract simplePayment{ function sendPayment(...
0
votes
1answer
123 views

How can I use the payable function to transfer fixed ether in a transaction?

contract MyContract { address payable[] recipients; function sendEther(address payable recipient) external payable { recipient.transfer(1 ether); } } Error- transact to ...
1
vote
1answer
36 views

Paying the gas cost with the ether stored in the SC

Let's suppose that an entity deploys an SC and wants to perform an allocation (which computationally speaking has a high gas cost). The participants of this delivery (registered persons) must be the ...
0
votes
1answer
94 views

Could A Solidity Developer with Binance Chain Familiarity Explain This?

I am a large holder of a certain token. We recently notice that one wallet where liquidity was being sent regarding 8% of transactions was unwrapping and selling those tokens. We confronted the ...
0
votes
1answer
135 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 ...