AnswerBun.com

use inline action with eosio.token

EOS.IO Asked by AhmadKajjan on August 20, 2021

Hello guys i am trying to build a contract that act with eosio.token to make a transfer from my contract using inline action with the eosio.token contract
here my code

#include <eosio/eosio.hpp>
#include <eosio.token/eosio.token.hpp>

using namespace std;
using namespace eosio;

class [[eosio::contract("test")]] test:public eosio::contract{
    private:
        void make_transfer(name& from,name& to,asset& quantity,string& memo)
        {
            token::transfer_action transfer{"eosio.token"_n, {from, "active"_n}};
            transfer.send(from,to,quantity, memo);
        }

    public:
        test(name receiver,name code,datastream <const char*> ds):contract(receiver,code,ds){}
        [[eosio::action]]
        void trade(name from,name to ,asset fromcoin,asset tocoin,string memo)
        {
            make_transfer(from,to,fromcoin,memo);
        }

};

i got these error

Error 3090003: Provided keys, permissions, and delays do not satisfy declared authorizations
Ensure that you have the related private keys inside your wallet and your wallet is unlocked.

    Error Details:
    transaction declares authority '{"actor":"alice","permission":"active"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [{"actor":"test","permission":"eosio.code"}], provided keys [], and a delay max limit of 3888000000 ms
    pending console output: 

2 Answers

I ran into the exact same issue. You have to add your smart contract to the active permission. Check out this answer, it will solve your problem:

https://eosio.stackexchange.com/a/1718/1010

Answered by mschoenebeck on August 20, 2021

You can't do this like what eosio.system does. eosio.system is usually deployed on eosio, privileged account, that can send any action with any permission.

Any inline actions your contract send is executed with permission [email protected]. If you want to make USER's token to be transferred by your contract, USER need to add [email protected] to [email protected]. (but it means your contract can send any action with user's active permission)

In this case, it is better to make a notification handler than make your action transfer user's token.

[[eosio::on_notify(eosio.token::transfer)]]
void on_token_transfer(name from, name to, asset quantity, string memo) {
  do_something_what_you_want_to_do_when_receiving_token();
}

Answered by conr2d on August 20, 2021

Add your own answers!

Related Questions

What is the difference between std::string and eosio::string?

1  Asked on January 5, 2022 by phillip-hamnett-eos42

   

How to use scatter without node.js?

2  Asked on December 11, 2021

 

Ico smart contract update

2  Asked on November 22, 2021 by efraim

   

How does one print an iso timestamp in a smart contract

1  Asked on August 20, 2021 by chris-de-jong

 

can’t generate abi when using map

1  Asked on August 20, 2021 by vishal-singh

   

Action setprods on EOSIO v2.0 private chain

2  Asked on August 20, 2021 by scott-owen

 

How to unstake ALL my EOS from EOS Voter Greymass

1  Asked on August 20, 2021 by gianmaria-toccotelli

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP