I have a smart contract which has a payable action defined. I want to cover the cost of transfering token to my contract, what's the best way to do this? Thanks.

3 Answers 3


It's hard to send inline transfer while executing your action. (@eosio.code permission needs to be added to user's @active permission in advance)

void signup(name user) {
   /* To make user token transfer in action is difficult */

Triggering your action by notification from eosio.token::transfer would be a better solution. User needs to send token with pre-arranged string.

void on_transfer(name from, name to, asset quantity, string memo) {
  if (from == get_self()) return;

   * parse memo and do necessary things
   * for example, memo can contain action name and its args.
  • Sorry, I didn't make myself clear. I understand how payable actions work. What I am asking is how to cover the cpu/net cost of user transfer token to my smart contract. Currently user needs to stake a lot of EOS to make transfer, I am trying to find the best way to cover that cost. I understand how ONLY_BILL_FIRST_AUTHORIZER works, but I don't want to leak my private key, even with a custom permission. Dec 2, 2019 at 4:38
  • @TommyJiang I don't think there is an elegant way to do it in general. You need to sign user's transaction to pay by your account, so there can be two ways, to provide some frontend (website or wallet application) to handle user's signed transaction (which adds your signature prior to user's), or expose private key with custom permission as you mentioned.
    – conr2d
    Dec 3, 2019 at 7:31

For people who might have similar question in the future, here is the outline how I am solving it today.

In a nutshell, you need your own API endpoint. The private key is saved in your API server, which will sign the first action, hence paying for the cost of whole transaction. Aaron Cox from Greymass explained it very well here, https://decentium.org/jesta.x/eosio-systemc. To implement it with Scatter, nsjames has a good example here, https://gist.github.com/nsjames/44d9c18879342449a211c49e53c74ccb.

If anyone has a way to do this securely without setting up an API endpoint, please comment.


you can follow this guide to pay cpu/net for users. https://cmichel.io/eosio-how-to-pay-for-users-cpu/

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.