2

I have two accounts viz. account1 and account2. I set my contract using account2. Now, I am sending 0.1100 EOS from account2 to account1 as a deferred transaction. I am using the following function which invokes a function transfer.

      void second::send(account_name from , account_name to ,asset  quantity,string  memo,uint64_t delay) {
            eosio::transaction t{};

            t.actions.emplace_back(
                eosio::permission_level(from, N(active)),
                account1,
                N(transfer),
                std::make_tuple(from,to,quantity,memo)
            );
            t.delay_sec = delay;
            t.send(N(memo), from);
        }

I am passing from ,to,quantity and memo to the action send. If I hard code the value of account1, it works and if I set it to some other account it gives the permission exception.
So, now I am confused how to set the correct permissions. Thanks

1 Answer 1

1

I'm not quite sure in your code what's account1 as it's not defined anywhere. Did you mean N(account1)? Also, what does account1::transfer() look like? Are you trying to transfer EOS tokens? You should probably be using eosio.token as the account to which you send the action then.

Here's an example of a contract that manages the transfer of tokens

#include <string>
#include <eosiolib/eosio.hpp>
#include <eosiolib/asset.hpp>

using std::string;
using std::make_tuple;
using eosio::action;
using eosio::contract;
using eosio::permission_level;
using eosio::asset;

class passtokens : public contract {
  public:
      passtokens (account_name account) : contract(account) {}

      void sendtokens(account_name from, account_name to, asset amount, string memo) { 
          action(
            permission_level{from, N(active)},
            N(eosio.token),
            N(transfer),
            make_tuple(from, to, amount, memo)
          ).send();
      }
};

EOSIO_ABI( passtokens, (sendtokens) )

Give permission to the account that uploaded the contract above to use your active authority under their eosio.code authority:

$ cleos set account permission <your-account> active '{"threshold": 1,"keys": [{"key": "<your-key>","weight": 1}],"accounts": [{"permission":{"actor":"passtokens","permission":"eosio.code"},"weight":1}]}' owner -p <your-account>

then send a transaction:

$ cleos push action passtokens sendtokens '["<your-account>", "<account-you-want-to-send-tokens-to>", "50.0000 EOS", "memo message"]' -p <your-account>
3
  • we have to give permission to the account with which we created our contract right ? Commented Aug 2, 2018 at 10:56
  • 1
    yup. in my example above that's passtokens as it assumes a $ cleos set contract passtokens passtokens/
    – confused00
    Commented Aug 2, 2018 at 11:07
  • What does active authority provide us , Does we set the contract with the same account with which we set active authority under their eosio.code.. Commented Aug 7, 2018 at 4:19

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.