I have written an action transfer in my contract which is as below

// @abi action
void second::transfer( account_name from,
                      account_name to,
                      asset        quantity,
                      string      memo  )
{
    eosio_assert( from != to, "cannot transfer to self" );
    require_auth( from );
    eosio_assert( is_account( to ), "to account does not exist");
    auto sym = quantity.symbol.name();
    stats statstable( _self, sym );
    const auto& st = statstable.get( sym );

    require_recipient( from );
    require_recipient( to );

    eosio_assert( quantity.is_valid(), "invalid quantity" );
    eosio_assert( quantity.amount > 0, "must transfer positive quantity" );
    eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
    eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" );

    //print("balance of account from before transaction______",from.balance.amount);

    print("before transaction ______________________________account before_____________________________________________");
    asset value;
    printBalance(from,value);
    printBalance(to,value);
    sub_balance( from, quantity );
    add_balance( to, quantity, from );
    printBalance(from,value);
    printBalance(to,value);
    print("transfer _____________________account after________________________________________________________");

}

My contract name is second and I set the contract with my account name firstname , I also have a second account secondname and i set the permission as given

cleos --wallet-url http://wallet:5555 -u http://server:7777 set account permission firstname active '{"threshold": 1,"keys": [{"key": "EOS5BbbeRJizvAUq27RLFXWtabMfVgs9MjYUBJ8Y5cwvoDCYnnPyp","weight": 1}],"accounts": [{"permission":{"actor":"firstname","permission":"eosio.code"},"weight":1}]}' owner -p firstname

I had issued 10000.0000 EOS to account firstname, but when I send EOS from firstname to secondname using the following command

cleos --wallet-url http://wallet:5555 -u http://server:7777 push action firstname transfer '[ "firstname", "secondname", "1.0001 EOS", "message"]' -p firstname

I get the following error : 845758ms thread-0 main.cpp:2350 main ] Failed with error: Assert Exception (10) condition: assertion failed: unable to find key

my wallet is unlocked and running on port 5555 and nodeos running on port 7777. Am I doing something wrong while setting permission ?

PS: I am a little bit unclear about setting permissions.

This issue does not relate to account permissions. Permission errors would typically look like this:

Error Details:
transaction declares authority '{"actor":"player","permission":"active"}', but does not have signatures for it.

This error main.cpp:2350 main ] Failed with error: Assert Exception (10) condition: assertion failed: unable to find key indicates an issue in your smart contract cpp code. My guess would be that it is unable to find your token symbol here:

const auto& st = statstable.get( sym );

Are you sure you have created a token before trying to find it by symbol? How does your statstable and index declarations look like? Can you check if this table contains the symbol you are trying to .get()?

  • First I created the tokens and then I try to issue the token to a account than this error occur . – Nirdesh Kumar Choudhary Aug 10 at 6:44

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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