0

on the bitcoin network I generate a new address for each payment I am to receive. this way I can associate the address with the sender and I can tell when the payment has been made by monitoring the address. the payments all fall into my one wallet

on EOS there are accounts so payments to me would be made to my account. how can I therefore tell when a payment has been made to me by a particular payee? can I read the transaction log somehow (using eosjs) and find the identity of the sending account there?

1

TLDR; Yes, you can read the transaction log by sourcing the blockchain with tools like Demux or even trigger some actions on-chain by apply-ing your smart contract on messages to eosio.token.

I am quite not sure what you mean by making another "address", but for the second question, yes, it's possible.

1.If the subsequent actions after token transfer is executed on-block, you can set your contract to check for transactions to eosio.token which is the contract we interact when we transfer EOS system token.

EOSIO's action can be thought as interaction between message and its handler. Think of it as registering your contract to list of handlers of messages to eosio.token. The way you achieve this by manipulating dispatcher, and in specific, the apply function. I'll leave a simple sample code to help you catch a grasp.

void apply(int64_t receiver, uint64_t code, uint64_t action) {
    if( (code == receiver && name{action} != "transfer"_n) || (name{code} == "eosio.token"_n && name{action} == "transfer"_n)) {
        switch( action ) {
// This transfer function is one implemented on your contract, not eosio.token, and will handle the actions you need.
            EOSIO_DISPATCH_HELPER( foo, (transfer) )
        }
    }
}

DO NOT USE THIS CODE RIGHT AWAY! This code is simplified version without conditional statements to prevent malicious actions.

Playing around dispatcher is extremely dangerous so take your time on your own testnet before deploying it on the mainnet. This link might be helpful for you.

2.If the subsequent actions need to be done off-chain, consider using frameworks such as Demux. Demux is EOSIO official backend infrastructure built with javascript and is node-comaptible. When desired action happens, the action watcher you implemented will trigger action handlers which does the actual processing you need. Look at the examples code in github for more info.

|improve this answer|||||
  • thanks for the very detailed answer but I'm not sure how it relates to my question. perhaps as clarification: a customer needs to send me money for a specific use. in bitcoin I create a fresh address for my wallet and he deposits funds. I check the balances of the addresses I have handed out and when the right amount appears in the address I gave him, I know he paid. how can I accomplish the same thing in EOS? – ekkis Mar 6 '19 at 20:40
  • @ekkis By using custom dispatcher stated above, you can, for example, set your own contract to be triggered when someone transfers tokens to you. Perhaps then you can place a table entry in your contract about how much token you have received and check whether it has reached a certain amount and can process whatever you offered the client. – Jinu Mar 7 '19 at 1:48
  • 1
    Also, you can add some id value in the memo field of the transfer operation. For example in our marketplace you purchase by transfering EOS to our contract, with the memo {"inventoryId": 1} and our contract parses that, as described above. – Martin Wawrusch Mar 7 '19 at 3:07
  • @Jinu, the thing is I don't have a contract. I have an account and I just want to be paid and know what I'm being paid for – ekkis Mar 8 '19 at 2:05
  • 1
    @ekkis newer dapps abstract that away. The user never sees that part of the memo field. But yes, transfering to binance is always frightening. All because accounts cost money... – Martin Wawrusch Mar 9 '19 at 3:06

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.