2

I need help for an issue developing an EOS dapp. I want to call a contract function when someone transfer EOS to my contract. For this i used the apply method to call the function upon any transfer to my contract. This contract works fine on Local chain but getting error on testnet.

Here is the error that we get :

Error 3100006: Subjective exception thrown during block production
Error Details:
Cannot charge RAM to other accounts during notify.

Below is the code of apply function:

#undef EOSIO_ABI
#define EOSIO_ABI( TYPE, MEMBERS ) 
extern "C" { 
void apply( uint64_t receiver, uint64_t code, uint64_t action ) { 
      auto self = receiver; 
      if( action == N(onerror)) { 
         /* onerror is only valid if it is for the "eosio" code account and authorized by "eosio"'s "active permission */ 
         eosio_assert(code == N(eosio), "onerror action's are only valid from the \"eosio\" system account"); 
      } 
    print( "receiver, ", name{receiver} );
    print( "code, ", name{code} );
    print( "action, ", name{action} );
    TYPE thiscontract( self ); 
      if(code == N(eosio.token) && action == N(transfer) ) { 
    thiscontract.buy(unpack_action_data<eosio::currency::transfer>());
         switch( action ) { 
                break;
            EOSIO_API( TYPE, MEMBERS ) 
         } 
         /* does not allow destructor of thiscontract to run: eosio_exit(0); */ 
      } 
   } 
} 
1

This error means you are trying to charge someone RAM through an action that isn't specific to your contract.

The user wants to just send money, and they wouldn't expect that they would be charged RAM for a transfer. So somewhere in your code you use multi_index::emplace, and you set the payer argument to the user's account. This is fine if the code is called by an action in the contract, but not from an external action that involves the contract such as transfer. If you must do an emplace in a transfer, then you will have to pay for it yourself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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