Let’s say a a contract calls inline or deferred another contract. Can it choose who pays for the CPU? And in th case of an action called from a user transaction, it is possible to choose who pays for CPU? The caller, the receiver or even a 3rd party ?

  • is the second param of eosio::transaction::send() not paying for CPU in deferred transactions? or is that just ram – confused00 Aug 9 at 7:40
  • I think that's just the RAM cost to store the deferred tx in the deferred tx database, and the BP's pull it later, clear the RAM, and process as a transaction ... I think.... – Alex Aug 10 at 1:16

Officially, there is not way to decide. The smart contract pays for the CPU and bandwidth. As stated in the white paper:

Receiver Pays

Traditionally, it is the business that pays for office space, computational power, and other costs required to run the business. The customer buys specific products from the business and the revenue from those product sales is used to cover the business costs of operation. Similarly, no website obligates its visitors to make micropayments for visiting its website to cover hosting costs. Therefore, decentralized applications should not force its customers to pay the blockchain directly for the use of the blockchain.

A launched blockchain that uses the EOS.IO software does not require its users to pay the blockchain directly for its use and therefore does not constrain or prevent a business from determining its own monetization strategy for its products.

While it is true that the receiver can pay, EOS.IO enables the sender to pay for bandwidth, computation, and storage. This empowers application developers to pick the method that is best for their application. In many cases sender-pays significantly reduces complexity for application developers who do not want to implement their own rationing system. Application developers can delegate bandwidth and computation to their users and then let the “sender pays” model enforce the usage. From the perspective of the end user it is free, but from the perspective of the blockchain it is sender-pays.

However, you could force the users to pay for the CPU costs by changing the mechanism in which they call the action for your contract.

Instead of doing something like:

cleos push action account action data

You could do

cleos transfer your_account smart_contract_account "memo says the actual action you want to perform"

Then you use a function that stakes the tokens you receive and calls the appropriate action. When the action is finished you can transfer the tokens back to the user.

It may be possible to do this with a function that listens to delegatebw, but I haven't tried that yet so can't promise it will work.

  • "The smart contract pays for the CPU and bandwidth." ----- Are you sure about this? Some people say the caller pays for CPU/band and some say the contract. Do you have a source that says the contracts pays for CPU/band? – Alex Aug 10 at 17:05
  • 1
    I added the quote and link to the white paper where it is implied – Phillip Hamnett - EOS42 Aug 10 at 21:23
  • Thanks for the help. Can you help me with a really quick example... Say I'm making a coinflip contract, where the user guesses heads/tails and the contract pays them bet * 2 or keeps their money. Originally, it would be something like cleos push action eosio.token transfer '[user, contract, "1.0000 EOS","heads]' however the user has to pay the CPU for this ... I've tried. How to make this so that user doesn't have to pay for CPU/band? – Alex Aug 10 at 22:32

To perform any transaction in EOS, you need net and CPU bandwidth. It is not possible to decide who pays for CPU. It is possible in the case of RAM. RAM cost is imposed to who pays for storing app data in RAM.

If a contract calls inline or deferred another contract, then the caller(ie. caller contract account) must have the required amount of CPU bandwidth in order to perform the transaction.

  • Right, so your answer is that USER or CONTRACT always pays for CPU/band? User does, right? I understand that you can decide who pays the RAM cost... – Alex Aug 10 at 17:07

Your Answer

 
discard

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.