Hot answers tagged

16

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 type system at compile-time. The difference between payable and non-payable addresses is gone in the compiled contract code. Built-in methods You can use ....


12

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 will accept Ethers it should be declared with a payable modifier function save() payable { numDonations++; }


10

Yes, a contract can have Ether balance without any payable function. There are three ways to do it: 1) selfdestruction. Another contract self destructrs and sends its remaining Ether to your contract 2) Target of mining. Ether rewarded from mining can't be refused. 3) Ether sent to the contract before the contract exists. More details about these ...


8

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.4.0; contract bet{ uint256 public bet; event received(string msg); function () payable{ bet=msg.value; received("bet received");...


7

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 == 0) throw; to your function.


7

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 ether and allows for transferring is shown below. Only the person that deploys the contract will be able to transfer the ether. pragma solidity ^0.4.24; ...


6

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 fantasy. It simply means 1000000000000000000 (or 1e18) Wei. Ether tokens have 18 decimals. Let's say we use 6 decimals instead and you want to buy ten tokens, ...


6

Here is how to cast address to address payable: address addr = 0x****; address payable wallet = address(uint160(addr)); And contract cast to address payable: MyContract addr = MyContract(0x****); address payable wallet = address(uint160(address(addr)));


5

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 transaction sender to indeed send this ether to the contract.


5

Oh boy I'm stupid. address payable[] users works. Nevermind people. This question never happened...


5

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 msg.sender should be payable. A word of caution. selfdestruct is an inelegant way to stop a contract and could lead to non-trivial problems. Consider using ...


4

There's no way to stop a transaction from being mined, but you can check the gas price using tx.gasprice and not process transactions that are above a certain gas price, e.g. function() payable { require(tx.gasprice<30000000000); //30000000000 is 30 gwei //if gas price is higher than it, the tx will fail ...


4

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.deposit(myData, {value: 100, from: myAccount}); if the function had a second parameter you wanted to pass in you could do: instance.deposit(myData, myOtherData, {...


4

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. Mutability guarantees are, in order weak to strong: payable, implicit nonpayable, view, and pure. Your implementation MUST meet the mutability guarantee in this ...


4

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 CallAnotherContract. In Solidity's documentation, it states the feature of delegatecall: The purpose of delegatecall is to use library code which is stored in another ...


3

Those examples date from a version of solidity prior to when the payable modifer existed. I believe it was introduced in version 0.4.0, released on September 8, 2016. The blog post you link to dates from July of 2016


3

Short answer is Contracts are full participants, so when someone sends funds, then the contract has the funds. The contract can then decide if/when to send the funds and to whom. In your use-case, it implies keeping track of who is owed funds. You would do that as funds are received. Very sketchy example to help illustrate the flow. pragma solidity ^0....


3

The latter. The total ether required to make a transaction is amount + gasLimit * gasPrice (amount being how much ether you're sending). So you need to set aside enough ether to cover the maximum the transaction may cost for gas. In your example of needing 50000 in gas, you'd want to send, say, 1 ether - 50000 * 1 gwei and specify a 1 gwei gas price.


3

This line: recipient.transfer(amount); transfers amount wei from the contract's balance to the recipient. This line: recipient = msg.sender; means that the recipient is the account that called the function. So when you call the function from the address 0xca35b7d915458ef540ade6068dfe2f44e8fa733c, with the parameter 10, that address will receive 10 wei, ...


3

If you are using Solidity 0.5.0 or greater, you will need to make buyer a payable address. You can do this by adding payable to the buyer declaration: address payable buyer;


2

The address the contract is deployed to receives the payment. It is up to the contract to manage whatever balance it holds. To send that value to another address object, you call the address member transfer(value). So to fill out your payMeBack()... function payMeBack() { require(<some condition>); if(!client.transfer(gainedWei)) throw; // ...


2

The issue is that when Payment inherits from Reference ("is Reference") this implies it needs to implement any unimplemented functions in Reference (i.e. "getAmount") which you don't do - hence the contract won't be created. Looking at your code, I can't really see why you'd want Payment to inherit from Reference. You don't rely on having a getAmount in ...


2

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.send() in particular sends only 2,300 gas (at time of writing), known as the "stipend". The low budget allows a very simplistic fallback function to execute. ...


2

Update Since version 2.3.0 web3j generates wrappers with additional argument weiValue for payable functions. E.g. such code is generated public Future<TransactionReceipt> pay(Utf8String name, BigInteger weiValue) { Function function = new Function("pay", Arrays.<Type>asList(name), Collections.<TypeReference<?>>emptyList()); ...


2

Throw this one in as the fallback, similar to what Sebastian said: function() payable {}


2

it always failed when I sending funds to the contract This sounds as if you attempt to send Ether to the smart contract without any further data - and hence without calling any specific function. If you "just send Ether" to the smart contract, a special function without a name called fallback function is invoked. In your case, this fallback function also ...


2

See https://bitcoin.stackexchange.com/questions/39132/what-is-gas-limit-in-ethereum Additionally, blocks, too, have a field called gas limit. It defines the maximum amount of gas all transactions in the whole block combined are allowed to consume. So as you assume, the transaction might be too complex.


2

Anyone can call any public function on your contract, by sending a transaction to that contract and including "data" that names that function. If someone sends a transaction with ether to a function, and the contract did not mark the function as payable, then the call will be rejected. If the contract did mark the function as payable, though, that ether ...


2

This sort of transfer can be done in two stages. The person who aspires to be good needs to first call vbToken.approve(<your contract's address>, 5) (or rather 5 * 10**decimals). This authorizes your contract to take 5 vbcoins from them. They then call sendVBCoins(5) (or, again, more likely 5 * 10**decimals). Inside sendVBCoins, you will call vbToken....


2

Fallback function does not execute because fallback function works if a transaction hasn't parameters which have a name of call functions. When I call paybaleFunction() my transaction which send to the contract have parameter which point on paybaleFunction(). More detail about this on Fallback Function


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