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 {

  using contract::contract;

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

  void ask(name user) {
    require_auth( user );
    delegate_resources( user );


  void delegate_resources(name user){


      // What code should be here?

      //permission level

EOSIO_DISPATCH( resource_delegating, (ask))

1 Answer 1


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

    eosio::asset quantity(1,eosio::symbol("EOS",4));
      eosio::permission_level(eosio::name(get_self()), eosio::name("active")), 
      eosio::name("eosio"), eosio::name("delegatebw"), 
      std::tuple(get_self(), user, quantity, quantity, false)

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.