1

I'm looking for any relevant code example or documentation describing how to make contract stake resources for some account. I'm aware of delegatebw function of cleos however, I need the following contract to stake 1 EOS for the users account CPU (or NET) whenever the user is calling ask()

#include <eosiolib/eosio.hpp>

using namespace eosio;

class [[eosio::contract("resource_delegating")]] resource_delegating : public eosio::contract {

public:
  using contract::contract;

  resource_delegating(name receiver, name code,  datastream<const char*> ds): contract(receiver, code, ds) {}

  [[eosio::action]]
  void ask(name user) {
    require_auth( user );
    delegate_resources( user );
  }

private:

  void delegate_resources(name user){

    action(

      // What code should be here?

      //permission level
      //name1
      //name2
      //memo
    ).send();
  }
};

EOSIO_DISPATCH( resource_delegating, (ask))
1

You would fill this part of the code in with the relevant action for delegatebw:

    eosio::asset quantity(1,eosio::symbol("EOS",4));
    action(
      eosio::permission_level(eosio::name(get_self()), eosio::name("active")), 
      eosio::name("eosio"), eosio::name("delegatebw"), 
      std::tuple(get_self(), user, quantity, quantity, false)
    ).send();
| improve this answer | |

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.