0

I need to write a contract that automaticaly mint nfts when tokens are being transferred.

So i have my :

[[eosio::on_notify("*::transfer")]] 
void logdeposit(name from,name destination, eosio::asset quantity, std::string memo); 

This is working fine and i am able to log incoming deposit on a table.

Now my problem is to understand how can i call actions on the behalf of my contract ?

What i am trying to to for testing is simply to return sent tokens.

So after my log deposits, i try to call this action :

sendtoken(destinationuser,returnedseed,"Returned leftover seeds.");

 ACTION seeds1::sendtoken(name to,asset quantity,string memo){
    require_auth(get_self());
    print("returning : ",quantity.amount," - ",quantity.symbol);
    action(
      permission_level{get_self(),"active"_n},
       name("testseed1"),
       name("transfer"),
      std::make_tuple(get_self(),to,quantity,"returning seeds")
    ).send();
 }

But that throw me a permission error. So i guess, because the on_notify was trigger by the user transfer it still uses its permission. That is fine for the log deposit action (which record in a table the current user deposit balance).

So here is my question :

  • From my log deposit action, how do I call other contract actions with the contract permission (and its important that those actions should only be able to be accessed by the contract, not public)

Thanks a lot :)

1 Answer 1

0

So i have found my problem, I had to add the eosio.code permission to my active key.

Since im in a local testnet, I follow this post, worked very well :

Add permission in eos studio

Now i have a new error :

"eosio: assertion failure with message: datastream attempted to read past the end"

Currently looking into it :)

Hope this will be usefull to others anyway !

1
  • pls mark your answer as correct solution for your initial question.
    – cmadh
    Commented May 12, 2022 at 10:46

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.