73 votes

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

Data storage and representation in the EVM The address and address payable types both store a 160-bit Ethereum address. The concept of payable and non-payable addresses only exists in the Solidity ...
Jesbus's user avatar
  • 10.5k
39 votes

How to cast address to address payable in solidity 0.5.0

Solidity 0.6.x: Here is how to cast address to address payable: address addr = 0x****; address payable wallet = payable(addr); And contract cast to address payable: MyContract addr = MyContract(0x*...
k06a's user avatar
  • 3,016
28 votes
Accepted

Solidity 0.5.x - make address array payable

Oh boy I'm stupid. address payable[] users works. Nevermind people. This question never happened...
Chris's user avatar
  • 1,302
24 votes
Accepted

Can a contract with no payable function have ether?

Yes, a contract can have Ether balance without any payable function. There are four ways how it's possible: selfdestruction. Another contract self destructs (by using the selfdestruct functionality) ...
Lauri Peltonen's user avatar
24 votes

Compiler solc expected a state variable declaration

instead of using function() public payable {} Use fallback() external payable {} with latest solidity we dont use function keyword. https://solidity.readthedocs.io/en/v0.7.4/contracts.html#fallback-...
Ashutosh Singh's user avatar
15 votes
Accepted

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

Elsewhere in the contract, find address admin; and declare it as address payable admin;. Alternatively, selfdestruct(msg.sender); because require(msg.sender == admin); ensures they are the same and ...
Rob Hitchens's user avatar
  • 55.2k
14 votes
Accepted

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

The code is correct but I lacked the understanding regarding the mechanics of how Ether is accessed and sent to contracts. I will explain to aid others in their advancement of knowledge... The ...
29A's user avatar
  • 347
14 votes

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

Yes, they store the same data, that is a valid ethereum address. The difference is that the compiler (at compile time) when encounter an “address payable” is ready to allow (if required in the ...
Rick Park's user avatar
  • 3,194
14 votes

why contract must have a receive()/fallback() to receive ether? isn't a payable function enough?

We can transfer ETH to smart contracts without calling a payable function. To handle these scenarios when someone sends ETH directly to a contract we use receive and fallback functions. If someone ...
Srikanth Alva's user avatar
13 votes
Accepted

Make function payable for a specific ERC20 token?

An ERC20 token is just another contract. The ERC20 standard gives you two functions that work together to help pay a contract: approve() and transferFrom(). If the token contract is called "token" ...
user19510's user avatar
  • 28k
13 votes

Transfer from contract address

If the ether is already in the contract and you do not have the functionality to transfer ether already implemented in it, the ether will be forever in the contract. A simple contract that receives ...
Jaime's user avatar
  • 8,340
12 votes
Accepted

Bad Jump Destination error

While you are using Solidity 0.4 you should define your payable function. if your contract will receive Etheres define in your code payable fallback: function() payable {} if you want any functions ...
Badr Bellaj's user avatar
  • 18.8k
11 votes
Accepted

What denomination should I issue my ERC20 token by?

Solidity can't do floating point. This is why we store and transact with the smallest unit available by your decimals. They are the only unit that actually exists, ie: Wei in Ether. "1 Ether" is a ...
diabetesjones's user avatar
11 votes
Accepted

What is the significance of making constructor payable?

payable means that you can transfer ether with the transaction. If the contract is designed that it needs an ether deposit on construction, then you can not hard code this. You have to allow the ...
ivicaa's user avatar
  • 7,519
10 votes
Accepted

How to set msg.value in solidity function call

If I understand your question correctly, you want to make a call from one contract to another contract's payable function and make an ETH transfer with it, if so you can do it with: address.function{ ...
Nikolay Deshev's user avatar
9 votes
Accepted

Testing Payable Functions From Truffle

Web3 offers a number of optional parameters which you can add to a function call: from - The address transactions should be made from. gasPrice - The gas price in wei to use for transactions. gas - ...
Shawn Tabrizi's user avatar
8 votes
Accepted

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

you need to use the Fallback function like in the code below. this function is executed when someone send Ethers to the contract without providing any data or calling a function : pragma solidity ^0....
Badr Bellaj's user avatar
  • 18.8k
8 votes
Accepted

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

"The called function should be payable" is a wild guess of a hint and usually wrong. The contract has reverted for any number of reasons. You will have to use debugging techniques to zero in ...
Rob Hitchens's user avatar
  • 55.2k
7 votes
Accepted

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

No. It's OK to have a function with the payable modifier not receiving any ether. If you want to ensure that your payable function receives some ether, you can add your own modifier or if (msg.value ...
eth's user avatar
  • 85.8k
7 votes
Accepted

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

Yes, the payable keyword makes the function capable of receiving the blockchain's native asset - such as Eth or BNB. If you try to send the native asset to the contract and there is no payable ...
Lauri Peltonen's user avatar
6 votes
Accepted

Is it possible to send Ether using delegatecall?

Exactly as @smarx mentioned, delegatecall does not do actual actions to the contract that you gave, a.k.a _contractAddress, but rather copy the code of function callMe() and execute in the ...
QYuQianchen's user avatar
6 votes
Accepted

Using payable functions in the remix ide

It is rather unintuitive on Remix, but there is a value input near the top of the panel (circled red). You can enter the value there before clicking on a function call. You'll need to do it for every ...
pbsh's user avatar
  • 2,441
5 votes
Accepted

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

As you're using truffle, you can check out how to interact with contracts via javascript here https://truffle.readthedocs.io/en/beta/getting_started/contracts/ basically this should work instance....
Adil's user avatar
  • 396
5 votes
Accepted

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

It appears the answer is to do with mutability, from the "Caveats" section of the ERC721 spec, Solidity issue #3412: The above interfaces include explicit mutability guarantees for each function. ...
AnAllergyToAnalogy's user avatar
5 votes
Accepted

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

Try myContract.someFunc("hello",100,{value: 2000000000000000000}).then(... Hope it helps.
Rob Hitchens's user avatar
  • 55.2k
5 votes
Accepted

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

I think I'm missing something You're definitely missing something - those are two different balances: msg.sender.balance is the ether balance of msg.sender balances[msg.sender] is the token balance ...
goodvibration's user avatar
5 votes

Ethers js deploy contract with balance, payable constructor

Just change initialBalance to { value: initialBalance } const deployedContract = await myContract.deploy({ value: initialBalance }); The deploy function takes constructor arguments followed by an ...
Soham Zemse's user avatar
  • 2,031
5 votes
Accepted

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

(That's a very long answer to a rather simple question, TLDR: BEP20.transfer() is an external call to a contract, payable.send() isn't) The difference between fallback and receive is well explained in ...
Foxxxey's user avatar
  • 4,307
5 votes

why contract must have a receive()/fallback() to receive ether? isn't a payable function enough?

receive() is for receiving ether without calling data. e.g address.call{value : 1 ether}(); payable function is for receiving ether with data e.g address.call{value : 1 ether}(abi.encodeWithSignature('...
Jiaming Li's user avatar
4 votes
Accepted

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

No. The gas amount and ether sent don't mix. Generally, all available gas forwarded with messages to other contracts (functions) but this can be controlled by specifying gas in Solidity. address....
Rob Hitchens's user avatar
  • 55.2k

Only top scored, non community-wiki answers of a minimum length are eligible