1

as far as i can tell it is somehow inconvenient to let the user of an contract "pay" for the cpu time. I thought that the one who manages the contract, has to stake for cpu/bandwidth, so user can use his contract. But now after i used some contracts on the blockchain, i was always the one who paid + i had to pay for the ram.

  • delegate/undelegate EOS to user is an option (but you have to wait 3 Days till you can use them again).
  • I read also somewhere to use inline transaction but these were also paid from the user (see example code):

test code for inline transactions:

#include "testeoscpuio.hpp"

using namespace eosio;
//@abi action
void testeoscpuio::doggos(){
    auto itr_dog = tb_dogs1.begin();


    if(itr_dog == tb_dogs1.end()){
        tb_dogs1.emplace(_self, [&](auto& d) {
                d.id = 2;
                d.number = 1;
        }); 
    }else{
        tb_dogs1.modify(itr_dog, _self, [&](auto& d) {
            d.number = 1;
        });
    }

    uint16_t b = 0;
    for(uint16_t i = 0; i < 20000; i++){
        b = b +i;
    }

}


//@abi action
void testeoscpuio::calc(){
    action(permission_level{ _self, N(active) },
            N(testeoscpuio), N(doggos), std::make_tuple()).send();

    for(uint16_t i = 0; i < 200000; i++){
        b = b +i;
    }
}

1 Answer 1

0

Another way would be to use deferred transactions as the contract can set the payer to _self in the second argument for transaction::send(), but the contract still needs CPU/NET for the initial action that triggers the deferred transaction.

contracts/eosiolib/transaction.hpp

 void send(const uint128_t& sender_id, account_name payer, bool replace_existing = false) const {
    auto serialize = pack(*this);
    send_deferred(sender_id, payer, serialize.data(), serialize.size(), replace_existing);
}

Otherwise, one may design second layer services that abstract the blockchain accounts and execute actions through an admin account while handling authentication off-chain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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