Linked Questions

1
vote
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
1answer
912 views

Call a payable function from a smart contract [duplicate]

Lets say we have contract A contract A{ function foo(uint8 value) payable{ require(msg.value !=0) do something ... } } and contract B contract B{ function bar(...
1
vote
1answer
573 views

Calling and funding a payable function from existing contract balance [duplicate]

If smart contract A has a balance of 1 ETH, can I call a payable function on Contract B, from a function in Contract A, with a msg.value that would be effectively withdrawn from the balance of smart ...
0
votes
1answer
453 views

How to call “payable function” via interface in solidity [duplicate]

I have a function marked as payable in contract A and I want to call it from contract B so that msg.value in contract A can have its desired value and contract A must have balance of sent amount , how ...
12
votes
2answers
8k views

How to send ether to a contract in truffle test?

For some reason I cant figure out how to send ether to a contract when testing in truffle. This is my attempt: await myContract.send(10, {from: accounts[0]}); the error message is: Error: VM ...
2
votes
1answer
1k views

What happens when you use multiple “call” arguments?

I have a piece of code like so: address x=0x01234..; x.call(data1, data2, data3); Will this do what I expect and call the contract at address x while passing the data in concatenated like data1+...
1
vote
1answer
366 views

How to deposit to WETH in Solidity 0.6 and above?

Solidity 0.6.0 introduced a breaking change in how ETH transfers are performed. The following doesn't work anymore: weth.deposit.value(amount)(); What is the latest syntax for depositing ETH into the ...
2
votes
2answers
133 views

How can a contract send a fee to another contract?

Here is the code confusing me: function createRelay () returns (bool success) { relay = new Relay() bool success = Relay(relay).setRelay(someInt, someAddress); if (success) { ...
2
votes
1answer
72 views

Is there a way for contracts to share balances?

I am looking for a way for people to be able to send ethers to two contracts (two different address). But I need the balance between these two contracts to be shared. So that one contract can use the ...
1
vote
1answer
70 views

Direct and separate funds into two different payable functions

Basically I have this code where I'm trying to divide a specific amount of ether into two different function calls within the contract. function singleTransaction(arg1) payable { require(msg.value ...