Obyte is an open crypto platform that uses a Directed Acyclic Graph (DAG, directed graph without cycles) as a transaction registry instead of a blockchain, with free and equal access to the registry for all participants. DAG, unlike the usual blockchain for everyone, makes it possible to send data to a distributed registry directly without the participation of miners due to the rejection of blocks and from strict ordering of transactions. Compared to blockchains, the DAG architecture does not need privileged classes of users, such as miners, forgers or block producers, so there are no intermediaries between the user and the registry on the network, and everyone has equal and direct access to add transactions to the registry.
In this article, I would like to talk about Obyte, Autonomous Agents and compare all this with Ethereum.
What are Autonomous Agents?
This is a program whose source code is stored in the registry (DAG) and has its own address, similar to the addresses of any other network participants. The program describes the actions that will be performed in response to sending coins and data to this address. If you are familiar with Ethereum smart contracts, Autonomous Agents are very close in meaning to them.
An example from life is a vending machine. In response to the product number typed on the keyboard and entering the amount, the device gives the user the product itself. There is one important difference between AA and vending machines: vending machines are controlled by their owners, and users only hope that the device’s actions will match the user's expectations. Autonomous Agents are truly autonomous: the entire program is stored in the DAG, its source code is visible to all network participants, it cannot be changed, disabled or deleted.
For example, you can program AA to exchange tokens. For programming, the language developed for these tasks is Oscript.
Obyte also has the concept of smart contracts, but they are not the same as AA or Ethereum smart contracts. The main difference between AA and Obyte smart contracts is that smart contracts, like regular contracts in the real world, operate between two participants and say under what conditions a contract can be executed. Simply put, a set of conditions that allow or prohibit a transaction. At the same time, an autonomous agent is an independent programmed participant, interacting with which we initiate its response (new transactions, etc.).
The execution of the AA code begins after the trigger transaction has stabilized (that is, there was consensus on the transaction and double spend is definitely absent). Each full-node will execute AA code on its copy of the registry, and records the result of execution only in its database. There is no need to relay the result of execution to other nodes, because the state of all participants in the network is the same and the result of the execution is also deterministic and the same for everyone. The final state of the registry is determined only by the rules of AA execution, and is not controlled by miners, nor voters, nor by anyone else.
What are they needed for?
AA allows decentralized mode to create things like
- options
- futures contracts
- algorithmically stable coins
- synthetic assets
- other derivatives
- collateral lending
- margin trading
- decentralized exchanges
- decentralized oracles
- payment channels
- economic games
- market makers
- automatic investment portfolio management
And much more…
Transparency for the user
Obyte from the first day of existence provides the opportunity to conclude a smart contract between people in a form understandable to humans. Transparency and ease of perception by users have been and remain one of the main principles in creating the platform.
Despite the fact that Oscript is a programming language, and was created for perception by the machine and programmers, and not ordinary people, we tried not to depart from our principles. Therefore, for people who are not familiar with programming, the GUI wallet will try to interpret the AA code before the transaction is completed and show the person the result in a way that he understands:
Oscript - stand-alone agent language
Developers familiar with any C-like language will have no difficulty working with AA.
First, I would like to make out the features.
AA only works on triggering transactions. It can be either just payment, or AA data transfer. For example, you pass the data
{foo: 'bar', value: 100} and they will be received by AA as
input , and based on this, the actions are performed.
What AA has access to
- to any variables describing the current state of the DAG
- Amounts received in trigger transaction
- data from transaction trigger
- who sent the trigger transaction
- state variables of our and other AA
- access to various public data from the DAG, such as data_feed from oracles, real name attestations, etc.
- balances of our and other AA
- asset information
Oscript Features
Oscript - NOT Turing the complete language, however, in its arsenal there are:
- arithmetic operations
- logical operations (and, or, etc.)
- comparisons
- string concatenation
- some math functions
- cryptographic functions (hash creation, signature verification)
- branching (if / else)
- no loops and functions (to prevent infinite recursions). More details can be found in the manual at this link
To control the use of resources and prevent malicious scripts, AAs are limited to a maximum of 100 labor-intensive operations, such as crypto functions or database accesses. Verification occurs at the time of deployment of the Agent code.
But there are no complicated formulas for calculating the cost of AA performance. There are no such formulas at all, code execution is free, users, like AA himself, pay only for adding data to the DAG registry, like any other network members - 1 byte in Obyte currency for each byte of data added to the DAG. However, AA must maintain its balance in bytes no less than the size of all state variables it stores.
If, on execution, AA triggers the execution of another AA, then first the resulting transaction of the first AA will be recorded in the registry, and only then will the next AA begin to execute.
Autonomous Agents in Action
Now we will write the simplest ping-pong script. We send AA money, he leaves some amount to himself and sends the rest back. We will solve the same problem on two platforms -
Obyte and
Ethereum, and compare. In Ethereum, similar AA entities are commonly referred to as smart contracts (although Ethereum white paper calls them autonomous agents once).
Ethereum
I will do everything through
geth. Run the node in
light mode and wait for synchronization.
geth --testnet --ws --wsapi "admin,db,eth,net,web3,personal" --syncmode "light" --allow-insecure-unlock
Now we have two scenarios:
- wait until peers are detected and synchronization begins
- add peers manually
I chose the second option. And
rfikki and his
ready-made list of commands come to the
rescue . We connect to the node and add peers:
geth attach ws://127.0.0.1:8546 admin.addPeer("enode://bc827e035cf3a42c249374be7ddc9c2fb819765c440116cf01aa6a8d70d03043d29ccd42b32a283f5ab08294467eb3b92fc40111e9af1770c84bc116edae89c0@104.248.199.52:30303"); admin.addPeer("enode://2d86877fbb2fcc3c27a4fa14fa8c5041ba711ce9682c38a95786c4c948f8e0420c7676316a18fc742154aa1df79cfaf6c59536bd61a9e63c6cc4b0e0b7ef7ec4@13.83.92.81:30303"); admin.addPeer("enode://053d2f57829e5785d10697fa6c5333e4d98cc564dbadd87805fd4fedeb09cbcb642306e3a73bd4191b27f821fb442fcf964317d6a520b29651e7dd09d1beb0ec@79.98.29.154:30303"); admin.addPeer("enode://690c93ac2f6e6f711a175cc6a73a3cf3b649eea83c458ce34364c69d1b557bb408693f06bdf6fc31538a744d5c231fdd904cce5665d04ce165032c0fc009a208@104.248.199.160:30303");
After that, the synchronization process will begin, and in order not to lose time, create an account. To do this, we will write the following commands in our connection and set the password:
personal.newAccount();
In the console we will see the address, copy it and go to
faucet . Paste in the field and click send.
Now check the synchronization:
eth.syncing
And check the balance:
eth.getBalance(eth.accounts[0])
The preparation is completed and now we can move on to writing and publishing the contract.
Create a file, for example pingPong.sol and write our contract into it:
pragma solidity ^0.5.10; contract PingPong{ function deposit() payable public { msg.sender.transfer(msg.value - 20000); } function getBalance() public view returns(uint256){ return address(this).balance; } }
In this contract, we create two public functions:
deposit - call by replenishment and return minus 20,000.
getBalance - just shows us the balance of the contract address.
Next, we need to compile it, for this I use the
npm module solc :
solcjs -o . --bin --abi pingPong.sol
Now prepare the compiled files for quick download in the
geth client. Change the
abi file to look
var pingPongContract = eth.contract([{"constant":true,"inputs":[],"name":"getBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"deposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"}]);
And
bin to view
personal.unlockAccount(eth.accounts[0]) var pingPong = pingPongContract.new( { from: eth.accounts[0], data: "", gas: 500000});
Go to the
geth client and connect these scripts
loadScript('sol2/pingPong_sol_PingPong.abi') loadScript('sol2/pingPong_sol_PingPong.bin')
Where
sol2 is the path to your script folder. After executing the second script, he will ask you to unlock your account. Done.
Next, write `pingPong`. If as a result you see that the address is not empty - the contract has been published, if not - you need to wait a bit and try again.
After that, we will execute the
deposit function, sending the money, and check how everything went.
personal.unlockAccount(eth.accounts[0]) pingPong.deposit({from: eth.accounts[0], value: 500000});
At the output, we can see the transaction id. Copy it, we will need it later. Before this, we call the
getBalance function and we see there 20,000, which we subtract.
pingPong.getBalance()
Now let's switch to etherscan. There, you will see in “Internal Transactions” a return payment of 48,000. I got it like this -
https://ropsten.etherscan.io/tx/0xc3fab9f39f2ec32eadffc54608a61c3c77c4ac0f3630037b5c312d3b66ee85f8#internal
Obbyte
For publication we will use the
Oscript editor
Clean the template that it offers us. We will write from scratch. Minimum AA is an object with an array of messages.
{ messages: [] }
Since we will send the payment, we need to add an object with the properties indicating this to the messages:
{ messages: [ { app: 'payment', payload: { asset: 'base', outputs: [ {address: "{trigger.address}", amount: "{trigger.output[[asset=base]] - 20000}"} ] } } ] }
Here we see the standard metadata for the payment. They are changed using "{}" in the lines. To transfer values, the
trigger object is used; it stores information about the received payment. You can learn more about the syntax
in the documentation .
We paste this code into the editor and then click Deploy.
All!
AA published and below we see the address. Now we need a
testnet GUI wallet , install it and run it. Next, to get some test coins, go to the “chat”, select “Bot Store” and add “Faucet Bot” there. Our chat will open, click on the menu on the left and select "Insert my address"
Then we send and wait for the message that the money came to us: "Payment: ...". Next, we need to go to the main one and wait until the inscription “Including pending confirmation” disappears (a few minutes), this means that the received coins are confirmed and they can be used.
All that remains for us is to go to “receive”, insert the address AA, enter the amount “500000” and press “send”. Now we need to wait until the transaction stabilizes (checking the history). This is necessary to trigger. We’ll check if the money returned to us:
That's all, it works. By going to explorer
at AA, we can see that his balance has increased by 20,000 minus the fee for paying us. At Obyte, Autonomous Agents themselves pay a commission for the actions they perform.
findings
As we can see from the comparison above, Obyte is much easier to publish, write and control what happens. For example, in Ethereum it is far from always that we can correctly select the gas of an outgoing transaction, because of which it can be confirmed for a very long time. Among the advantages of Ethereum, one can single out its quick publication and confirmation (about one minute, depending on the gas supplied). While in Obyte publication takes place immediately, and the confirmation time depends on the network load, with a light load - about 10-15 minutes, with a large load - less than three minutes.
In the following articles we will analyze some interesting and lively examples, for example, how to implement simple DAO using AA and answer your questions.
Contest
In connection with the innovation, we invite developers to join the competition for the most interesting and impressive application of Autonomous Agents. The competition is already ongoing and will last until mid-October. As examples from already received applications, there are several crowdfunding AAs, two exchanges, various “registries” and reputation trackers, lotteries, games, etc. Every two weeks, a jury of Obyte team announces the best entries.
The total budget of the contest is
$ 38,000 (at the
GB rate at the time of launch).
You can read more about the competition
in this article .