5

Can I track received payments to smart contract on a block explorer or do I need to run a contract method for this? I need the amount and payment identification information (I need to identify the payer somehow - probably he will send some kind of tracking code as payload). Is the answer different for ETH and ERC20 tokens?

  • Received payments means ETH or ERC20 – Jitendra Kumar. Balla Feb 14 '18 at 14:38
  • 1
    I am interested in both answers – jeff Feb 14 '18 at 14:40
2

For ETH, you can check the amount the smart contract received without having to call any smart contract method, using any block explorer.

Programmatically, using an Ethereum node, you can call the eth.getBalance(<your address>) method to find the ETH balance of any address (including smart contracts).

For ERC20 tokens, you have to call the balanceOf(<your smart contract address>) method of the token's smart contract address.

As a proof, have a look at EtherDelta's smart contract on etherscan.io and see that the contract has ETH balance.

In order to receive payments reliably, it's best for you to generate 1 address/customer, so that your customers are able to send you funds from any wallet they might use.

  • thanks, currently we do 1 address/customer with bitcoin, I thought we could save some overhead handling all those addresses if having a smart contract – jeff Feb 14 '18 at 15:45
  • 2
    In order to be able to identify a customer uniquely, they'd need to have a way to send you some extra piece of information when they're making the transfer (an invoice id for example). As of right now, no ETH wallet supports that out of the box (yes, many of them have that data field which can be completed, but requiring your users to fill that correctly makes your payment system basically unusable by average Joe). With the exception of Ripple and Stellar, I'm not aware of any other blockchain that supports this feature out of the box. – Tudor Constantin Feb 14 '18 at 15:58
  • This answer is not useful at all: balance or amount payed cannot reliable identify an invoice because there may be many purchases which match in amount; wrt the last part where 1 address/customer is recommended: this is what's done in bitcoin-like blockchains, but ethereum doesn't allow you to send money from different origins in the same transaction, so this implies the merchant would need to pay the fees to move the amount from that address to another "accumulation" wallet, let's say, which is not efficient. Downvoting. – knocte Dec 12 '18 at 7:48
0

Getting balance for a given Eth account, you can call below method

eth.getBalance('<ADDRESS>'); //Geth Console

web.eth.getBalance('<ADDRESS>'); //Web3js

Tracking ERC20 payments you no need to write any smart contract. Just need call contractObject.balanceOf().

ERC20 Balances:

contractObj.balanceOf('<ADDRESS>');

Check web3js for live/event driven transfers.

Event Driven:

contractObj.Transfer(function(error, result){
  if(error){
        console.log("Error", error);
        return;
    }
    //result.args.
});

Filter get all the transactions from address and to address for a ERC token:

methodID = web3.sha3('Transfer(address,address,uint256)');
const allEvents = eth.filter({
  fromBlock: 0,
  toBlock: 'latest',
  address: <CONTRACT_ADDRESS>,
  topics: [
    methodID, 
    '0x0000000000000000000000008fa31452a2bf4840ba358ce316defb9b20ad92d3',//FROM 32 Bytes padding
    '0x0000000000000000000000008fa31452a2bf4840ba358ce316defb9b20ad92d3', //TO 32 bytes padding
  ]
});
allEvents.get(function (err, events)) {
  console.log(events);
}

For more details web3js:

http://web3js.readthedocs.io/en/1.0/

  • Thx. Getting balance is easy, I need to check whether a specific user has send me funds. And I don't want to rely on sender addres, but would like to give him some kind of identifier – jeff Feb 14 '18 at 15:28
  • @jeff, Updated ans. – Jitendra Kumar. Balla Feb 14 '18 at 15:36
  • thx, but I still only can Identify payers by sender address :( – jeff Feb 14 '18 at 15:47
  • @jeff To address is optional. Please read more about events... – Jitendra Kumar. Balla Feb 14 '18 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.