5

This is a great answer that describes the ways you can handle user permission levels for inline actions. According to that answer:

This can be done a few ways (ordered from most risky for the user to least):

  1. The user may allow contract@active to satisfy their @active permission
  2. The user may set up a sub-permission (for example @xfer), link that as the minimum permission to eosio.token::transfer and allow contract@active to satisfy that permission
  3. require that the transfer be explicit (not inline) and then use the notification that is sent to your contract to (temporarily) record the details and read/assert/process them in a second action directly to your contract.

However, I was hoping if someone can share some implementation examples of the 3 methods above?

I found this which might be an example on how to achieve method (1) above? Would be good to know how the other 2 methods are achieved.

2 Answers 2

1

It seems hard to find an example that can answer all your questions.

Below is an example of sending an inline action without permission. You can learn a lot by reading this article.

https://trybe.one/the-ultimate-end-to-end-eos-dapp-tutorial-part-2/

How about making a reference to each of these examples?

How about making examples by referring to this content?

As time goes on, I will make it. Let's make it together.

3
  • Thanks for your response. This tutorial was what actually prompted me to ask this question. There was an issue with the way they implemented the inline action without permissions (look at this comment in their medium article). I’ll continue to investigate this and will post what I find.
    – ken
    Commented Jun 30, 2018 at 3:55
  • Ok, you did. So what if you want to ask specifically what you want with this example? In fact, I did not know exactly what you wanted by looking at your question. Others may be like me.
    – smarteasy
    Commented Jun 30, 2018 at 12:10
  • Sorry for being unclear. The way they (the article) handled inline actions were incorrect, according to this comment. You need to set up a chain of permission for a contract to transfer tokens on behalf of a user. This is what I do not know how to do.
    – ken
    Commented Jul 4, 2018 at 3:40
0
  1. The user may allow contract@active to satisfy their @active permission

cleos set account permission MYACCOUNT active '{"threshold": 1, "keys":[{"key":"MY_PUBLIC_ACTIVE_KEY", "weight":1}], "accounts":[{"permission":{"actor":"CONTRACT_NAME","permission":"eosio.code"},"weight":1}], "waits":[] }' owner -p MYACCOUNT

  1. The user may set up a sub-permission (for example @xfer), link that as the minimum permission to eosio.token::transfer and allow contract@active to satisfy that permission
cleos set account permission MYACCOUNT xfer '{"threshold": 1, "keys":[], "accounts":[{"permission":{"actor":"CONTRACT_NAME","permission":"eosio.code"},"weight":1}], "waits":[] }' active -p MYACCOUNT
cleos set action permission MYACCOUNT eosio.token transfer xfer -p MYACCOUNT
  1. require that the transfer be explicit (not inline) and then use the notification that is sent to your contract to (temporarily) record the details and read/assert/process them in a second action directly to your contract.

So this one is slightly more complicated. First of all, you would set up a permission for the contract to withdraw funds from your account as shown in option 2. Then you would have to load a smart contract to your account, and that contract would have a notify action linked to the transfer function. In this notify action, you would basically write some checks that would tell you that the amount taken was as it was expected to be, and do whatever other checks are necessary as well. This still isn't foolproof, because even if you limit the amount of money that can be withdrawn to something small like 1 EOS, there is nothing stopping the contract from calling that action many times to drain your account and/or use up your CPU and NET bandwidth.

An example of how the smart contract might look:

// Set up the transfer function to be called if a transfer occurs
void transfer( eosio::name from, eosio::name to, eosio::asset quantity, std::string memo )
{
  if(from == get_self()) return;
  if(to == get_self() && from == CONTRACT)
  {
    eosio::check(quantity.amount == 10000, "I expect that CONTRACT only ever takes 1 EOS at a time from my account");
    // Add as many more checks here as are necessary
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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