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
30
votes
2answers
14k views

What's the difference between 'address' and 'address payable'?

I saw a Solidity smart contract where some variables were declared with the type address and some were declared with the type address payable. What are the differences between the two? Do they store ...
14
votes
1answer
1k views

Bad Jump Destination error

I wrote what I thought was a dead simple contract - a saving jar... you add value ("save") into the jar and when the balance of the contract reaches a certain amount ("target"), then I am able to ...
12
votes
2answers
7k views

How to cast address to address payable in solidity 0.5.0

Got address from 3rd-party library: address wallet = rlp[5].toAddress(); And wanna transfer some funds to it: wallet.transfer(amount); Got error: TypeError: Member "transfer" not found or not ...
12
votes
1answer
2k views

Can a contract with no payable function have ether?

The question in the title says it all. To the best of my understanding, the only way to deposit ether into a contract is by calling a payable function, and set msg.value larger than 0 (and of course, ...
9
votes
3answers
1k views

Why is there more than one payable function in a solidity contract?

When someone transfers ether to a contract address the payable callback (without name) function is called automatically. What I don't understand is why are there many examples with multiple payable ...
6
votes
4answers
5k views

Transfer from contract address

I created a contract with a payable function but the ether is stored in the contract I am looking for a way to transfer the ether to another address
5
votes
1answer
434 views

What are 'payable' state variables?

https://solidity.readthedocs.io/en/latest/solidity-by-example.html#simple-open-auction pragma solidity ^0.4.22; contract SimpleAuction { address payable public beneficiary; What exactly does ...
4
votes
1answer
4k views

Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested

function endSuply() public { require(msg.sender == admin,"only admin can end the token sale"); require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))),"balance not ...
4
votes
1answer
3k views

Compiler solc expected a state variable declaration

I try example from book Mastering Ethereum: contract Faucet { function withdraw(uint withdraw_amount) public { require(withdraw_amount<=10000000000000000); msg.sender.transfer(...
4
votes
2answers
3k views

How can a smart contract run when receiving ether directly, not through a function?

I have a smart contract with a payable bet() function. When someone sends 1 ether to the bet function, the contract is executed. I'd like the contract to run the same code when someone sends ether to ...
4
votes
2answers
2k views

What is the significance of making constructor payable?

Aren`t constructors used to initialize variable at the time of contract creation? In common patterns section in solidity documentation, payable constructor is used for withdrawal pattern example. ...
4
votes
1answer
528 views

Will payable modifier throw if no ether is sent to it?

Should I add a check to make sure Ether was sent along with the transaction or is that redundant?
4
votes
1answer
804 views

Why are the transfer and approve functions payable in the ERC-721 spec?

In the ERC-721 spec interface, the functions safeTransferFrom, transferFrom and approve all have the payable modifier. What is the reason for this? As far as I can tell, none of these functions ...
3
votes
1answer
2k views

Solidity 0.5.x - make address array payable

I'm trying to write a contract that uses an address[] array which should contain payable addresses. But apparently creating a payable address array doesn't work in solidity 0.5.x. All I'm trying to ...
3
votes
1answer
2k views

What denomination should I issue my ERC20 token by?

Following the "Create a cryptocurrency" tutorial on ethereum.org, I ended up with the following function (stripped down): function () payable { if (msg.value == 0) { return; } uint256 tokens =...
3
votes
2answers
3k views

Testing Payable Functions From Truffle

I'm trying to test a payable function from Truffle my function looks like so: function recordOrder(bytes32 orderNumber) payable returns(bool success) { if(msg.value==0) { return false;...
3
votes
1answer
5k views

How to pass argument/parameter to a payable function of a contract that has been already deployed, via web3 / javascript / truffle?

I'm wondering how to pass argument to a payable function of a contract that has already been deployed, via web3 / javascript / truffle. For instance, I see the following piece of code at: http://...
3
votes
1answer
2k views

Make function payable for a specific ERC20 token?

a method can be payable and then it's possible to send ether to the contract while calling it, and the function can check the ammount sent through msg.value. How can I make a function receive ...
3
votes
1answer
356 views

Transaction fee restrictions with solidity

Can I restrict transaction fee (gas price) for the payable method of the crowdsale contract. And if I can, how? And one more question, if I restrict fee and call revert() - this transaction will be ...
3
votes
2answers
563 views

Can a miner “cheat” my lottery smart contract?

I developed a smart contract that you: 1) Send 1 ether to an address, the contract saves your address 2) After 5 people have sent one ether, the contract chooses one address at random and sends the ...
3
votes
1answer
1k views

Send ether to a payable function from nethereum

I have created a payable function in a smart contract and deployed it in a private blockchain network. Now I am using Nethereum to make rpc calls to the geth node on which the network is running. But ...
3
votes
0answers
1k views

Hi i am getting error msg.value non-payable [duplicate]

I had this function function enter() { if (msg.value >10 finney) { uint amount=msg.value; uint payout; but i am getting error: ballot.sol:56:9: Warning: "msg.value" used in non-...
2
votes
2answers
3k views

Payable: Sent - Hold amount - Sent_back mechanism (Refund)

[Q] When following transaction get called: Bank.pay({"from": eth.accounts[0], "value": 1});, who retrieves the money, does the owner of the contract? (Sorry I get lost who actually gains the money). ...
2
votes
1answer
293 views

How to transfer wei from a contract to a specific address?

I was making an auction system and I wanted to make sure that when someone bid higher the contract would return the money to the address of the previous bid. pragma solidity >=0.4.22 <0.6.0; ...
2
votes
2answers
4k views

How to set msg.value in solidity function call [duplicate]

If I have a function: contract one { function buyTokens(address _beneficiary) public payable { require(msg.value == 1 ether); // do something... } } How do I call that ...
2
votes
3answers
299 views

why don't popular tokens have payable fallback

I'm referring to the source of of the most popular tokens on etherscan. It looks like they don't have any payable functions. How do they accept ether and transfer the tokens automatically when ...
2
votes
2answers
2k views

Gas limit dangerously high

When I tried to send ether to my contract, I get this error. Even if try to change the value of Gas Limit and Gas Price the transaction still fails. What could be the possible reason? What I ...
2
votes
1answer
66 views

Are the functions in this code missing the payable modifier?

These functions are transferring ether between balances, so why aren't they modified with payable?
2
votes
1answer
313 views

TypeError: push is not detected as a function for address payable dynamic array

I'm trying to add the manager address to the playes array. I get the following error: TypeError: Member "push" not found or not visible after argument-dependent lookup in address payable[] ...
2
votes
2answers
146 views

Instantiating a contract with ether

I have a factory contract that I need to be able to deploy with some ETH. I'm getting an error TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address. I ...
2
votes
2answers
1k views

How to accept bitcoin and transfer tokens from smart contract to sender ethereum address

I have created sample tokens Smart Contract with the payable feature/constructor, if someone pay from their Ethereum address to Smart Contract will get instant token into their Ethereum address. But ...
2
votes
3answers
473 views

Why is Fallback function not being executed?

I have a fallback function for receive ether on my contract and I have a function for send ether to my contract, also in my contract, I have withdrawal function. Why is the fallback function not ...
2
votes
1answer
2k views

Is it possible to call payable functions of smart contract using web3j’s smart contract wrappers?

How do we call payable functions of smart contract using web3j? UPDATE: I'm going to change generated smart contract wrapper class manually. Now I have: public Future<TransactionReceipt&...
2
votes
1answer
203 views

If a function is called with a certain gas amount, will msg.value == amount of gas sent?

My function needs gas to fulfill a transaction, but I don't want people accidentally sending Ether to it.
2
votes
1answer
60 views

How to add more logic to a payable function?

How can I add to a payable function the possibility for the buyer (a company, in my case) to add some details about itself at the moment of performing the payment (e.g. registered number and company ...
2
votes
1answer
216 views

Contract working on Javascript VM and not Web3 Provider, why?

Here is the code: Calling contract: pragma solidity ^0.4.24; contract Caller { address public called_address; constructor() public payable { } function set_address(address _addy)...
2
votes
1answer
75 views

How to extract int128 from msg.data as first argument?

Let's say we have Ethereum smart contract with fallback function: event onDeposit(int128 indexed key, address from, uint amount); ... function () payable public { require(msg.value > 0); ...
2
votes
0answers
126 views

Can I call a library function from a payable function?

I seem to get a revert each time I try this. I'm unable to get any useful revert message from truffle, so any assistance there might also help solve this. I have a library: library LibInterface { ....
2
votes
2answers
156 views

How to process Smart Contracts payable functions in batch?

I am aware that metamask will enable effective security for processing via the web browser a payable function action to a smart contract. What happens in batch? I have an API service which then ...
2
votes
0answers
2k views

Web3 - how to send transaction with some data and include Ether at the same time?

Using web3 0.20.3 I want to call function and send some Etherium at the same time. JavaScript Contract = web3.eth.contract(ABI); Instance = Contract.at('0x162b74ea16da6ae9d7f7b349eaeab2fcadf4e835')...
2
votes
0answers
30 views

Why not possible limiting gas but forwarding ether in creating this contract from Solidity documentation

In the Solidity docs Creating contracts via new there is an example: contract D { uint x; function D(uint a) public payable { x = a; } } and it states in the accompanying text: ...
2
votes
2answers
760 views

function () public payable modifier can trigger actions when sending tokens or only works when sending ether?

Modifier payable triggers an action when an address sends ether to a contract. For example: function () public payable { require(msg.data.length == 0); DoSomething(); } Is this ...
1
vote
2answers
699 views

Testing payable functions with truffle console - where do you input msg.value?

Trying to test my token contract using truffle console + ganache, lets say I have a payable function someFunc(string _string, uint256 _int), how would I call it with arguments "hello", 100 and msg....
1
vote
2answers
179 views

UPDATED : How to determine “payer address” in “address.transfer(amount)”?

Consider we a function as follows : address public recipient; function settlement(uint256 amount) public { recipient = msg.sender; recipient.transfer(amount); } Then the ...
1
vote
1answer
4k views

How do you send Ether as a function to a contract using Remix?

New to Solidity... When deploying a contract on a private blockchain using Remix, I am unable to execute payable functions. When executing these functions, the following error message displays: gas ...
1
vote
2answers
160 views

Best way to check balance? msg.sender.balance vs balances[msg.sender]

If I want to check if the payer has enough funds, should I use... msg.sender.balance or balances[msg.sender] ? I also see that people usually check balance in the following way: require((balances[...
1
vote
1answer
46 views

Someone Please Explain this “The concept of payable and non-payable addresses only exists at compile time not after the contract is compiled” [duplicate]

Actually I was reading this Answer https://ethereum.stackexchange.com/a/64109/55286 . And this person says The concept of payable and non-payable addresses only exists in the Solidity type system at ...
1
vote
1answer
809 views

Cannot send ether to a payable function in truffle unit test

I am debugging a bug happened on my truffle solidity test. I can narrow down the problem to an exception happened in the payable modifier. my contract code: import "zeppelin-solidity/contracts/token/...
1
vote
1answer
38 views

Paying contract can't inherit?

I have two contracts. One inherits a function that gets the value to be paid by the second one. If I remove the 'is Reference' and replace the values from the external function, the code pays, ...
1
vote
1answer
27 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 ...