0

Okay, so assume there's a Web API that offers some kind of service / computation at a given cost. This API itself relies on calling another API that also has a cost.

Would it be possible to set up payment in such a way that, the first API gets an ethereum contract whereby it will be awarded some amount of ether once it delivers the result successfully. And the first API creates a contract with the second API, whereby it will pay out the second API a percentage / fixed part of the funding it gets automatically when the first contract is paid out?

And if it is possible, how high do the costs have to be to justify the transaction fee? Transaction fee at the moment appears to be prohibitively high (0.21USD if I understand everything right). Are there plans to get transaction fees down significantly, or are Ethereum contracts just not supposed to be used for low value transactions?

1 Answer 1

1

In general terms, you can for sure award the owner of a service (an API makes no exception) according to some results. However keep in mind that the success condition cannot be checked direclty from the contract because contracts can only check what happens in the blockchain and cannot gather any kind of external data.

This is a consequence of blockchain design where all nodes perform the same computation. Imagine if all node would connect to a web service to assess some offchain condition. This is just impossible. Hence, to complete the design of your solution you might need a bridge between on chain and off chain. This usually comes in form of oracle, which is a software able to read data from the web and then produce a valid transaction to unlock money in a contract. Oracle can be human too. A software and so called provable honest implementation of oracles is Oraclize.it.

Regarding the second part of the question, about how to split the reward with a second API provider, this is pretty simple and a contract can manage this with few instructions. I insert some code here, but consider it more pseudo-code rather than actual code.

contract Reward{
address public api1=0x123;
address public api2=0x124;

bool goalAchieved=false;
address oracle=0x234;

function unlock (){
    //only oracle can unlock
    if (msg.sender !=oracle) throw;
    goalAchieved = true;
}


function () payable {
    //this receives funds from a customer
}

function redeem(){
    //only api1 can redeem
    if (msg.sender != api1)throw;
    if (!goalAchieved)throw;

    api1.send(this.balance / 2);
    api2.send(this.balance / 2);
}

}

Regarding transaction fee, the GAS needed my outcost the value of your API invocation. But this really depends on your specific use case. A transaction for every single API invocation could be an overkill, consider selling quotas of N invocations instead.

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.