Bitcoin Forum
May 07, 2024, 06:27:22 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: In solitidy how to keep listening the contract receiving ether  (Read 43 times)
myapple (OP)
Member
**
Offline Offline

Activity: 100
Merit: 11


View Profile
February 04, 2018, 06:28:18 AM
 #1

In solitidy program I want to detect how many ethers I received
How can I do this
I mean keep listening once the contract received the ethers I will know
BitcoinCleanup.com: Learn why Bitcoin isn't bad for the environment
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715063242
Hero Member
*
Offline Offline

Posts: 1715063242

View Profile Personal Message (Offline)

Ignore
1715063242
Reply with quote  #2

1715063242
Report to moderator
herecomesjohnny
Member
**
Offline Offline

Activity: 156
Merit: 13


View Profile
February 04, 2018, 10:30:38 AM
 #2

If you want to detect received amount of ether use msg.value as usual. Just don't forget to include the payable modifier.

_______________________________________________________________________________ _____________________________________________

To know how many tokens has your contract access to, you can execute from you contract tokenContract.allowance(msg.sender, this)
myapple (OP)
Member
**
Offline Offline

Activity: 100
Merit: 11


View Profile
February 04, 2018, 01:13:21 PM
 #3

thanks
for msg.value how to keep listening to the event of receiving ethers
herecomesjohnny
Member
**
Offline Offline

Activity: 156
Merit: 13


View Profile
February 04, 2018, 01:43:32 PM
 #4

thanks
for msg.value how to keep listening to the event of receiving ethers

Try to set up a Watcher to react whenever anyone sends a coin using your contract. Here's how you do it:


var event = token.CoinTransfer({}, '', function(error, result){
  if (!error)
    console.log("Coin transfer: " + result.args.amount + " tokens were sent. Balances now are as following: \n Sender:\t" + result.args.sender + " \t" + token.coinBalanceOf.call(result.args.sender) + " tokens \n Receiver:\t" + result.args.receiver + " \t" + token.coinBalanceOf.call(result.args.receiver) + " tokens" )
});
herecomesjohnny
Member
**
Offline Offline

Activity: 156
Merit: 13


View Profile
February 04, 2018, 01:48:37 PM
 #5

thanks
for msg.value how to keep listening to the event of receiving ethers


Also; Checking the balances of different accounts on the blockchain:

web3.eth.getBalance(web3.eth.accounts[0]);

web3.eth.getBalance(web3.eth.accounts[1]);
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!