You can do something similar to what you're doing with Bitcoin, but with Ethereum. The simplest way may be to run your own Ethereum node (since you don't want to use external services). From here, you can generate an account/address on-demand. For example, you can do this from the geth
console using [personal.newAccount("passphrase")][1]
or with nethereum. You can then poll the account balances until the desired amount is received (you might want to use a back-off algorithm like this or simply put a deadline for payment receipt) and then do the rest of your backend stuff to fulfill the order. If you accept payments this way, you can easily send the received amount into a master account. The downside to this is, unless you have replication, if your backend system goes down, you might lose the private keys for the accounts you just created. Also, hot wallets are involved, so theft is made easier (but if someone can compromise the backend, they can just have payments sent to their own accounts, anyway).
You can avoid this by pre-generating a set of accounts, as you suggested, using an automated method as described above. You are still able to check the balances of the accounts for payment purposes, but you won't be able to sweep the ether automatically. Instead of using a plain account, you could potentially create a contract to do that automatically, but would need to spend more gas (either you or your clients). If you use this method, you don't need to run your own node and can use something like a public blockchain explorer. The downside is you now need to trust the explorer to a) not give you false data, b) maintain good uptime, and c) not change their API all of a sudden.
See also How to list transactions from account address? .
When watching for events from web3, this is the format of the result you get when one is called:
{ address: '0x9c0ac1e0f0a8e0b01c7b652d5fbe094ddff48b81',
blockNumber: 704227,
transactionHash: '0x5887ba4e15d51e1cfddf626ecf416a0002085a1e0929fffe1f90ad69d5040081',
transactionIndex: 0,
blockHash: '0x5f485133ec662f556d88affccc18a358375de160178c6cf7cc0cec678d833a2a',
logIndex: 0,
removed: false,
event: 'ExampleEvent',
args:
{ argOne: BigNumber { s: 1, e: 0, c: [Array] },
argTwo: '0x374623456fa2' } }
So you can just get the TX from result.transactionHash
Event in contract:
event ExampleEvent(uint argOne, bytes32 argTwo)
Web3 code:
import exampleContractObject from 'path/to/ExampleContract.json'
ExampleContract = web3.eth.contract(exampleContractObject.abi);
contractInstance = ExampleContract.at('0x9c0ac1e0f0a8e0b01c7b652d5fbe094ddff48b81');
exampleEvent = contractInstance.ExampleEvent();
exampleEvent.watch((err, result) => {
// Do something
}
EDIT:
The Transfer event from ERC20 tokens would look like this:
{ address: '<contract_address>',
blockNumber: <block_number>,
transactionHash: '<transaction_hash>',
transactionIndex: <tx_index_in_block,
blockHash: '<block_hash>',
logIndex: <log_index>,
removed: <> ,
event: 'Transfer',
args:
{ _from: <address>,
_two: <address> ,
_value: <uint256>} }
Best Answer
After search couple hour I found some idea for accepting ether payment. First of all I need to create new account/address for every payment request where user can send ether and then poll the account balances until the desired amount is received. Once amount is received then it send to master account.