ENI Tutorial

Run Travis Node

What is travis? See here for instructions to start a Travis node.

Make sure to checkout to the lity branch.

go get github.com/CyberMiles/travis
cd $GOPATH/src/github.com/CyberMiles/travis
git checkout lity
make all
travis node init --home ~/.travis
travis node start --home ~/.travis

Get ENI Libraries

See libENI documentation for how to get ENI libraries or build your own ENI libraries.

Install the ENI libraries to Travis environment.

mkdir -p ~/.travis/eni/lib/
cp eni_reverse.so ~/.travis/eni/lib/

Use ENI in Your Contract

Create a contract file called Reverse.lity.

pragma lity ^1.2.4;

contract ReverseContract {
  function reverse(string input) public returns(string) {
    string memory output = eni("reverse", input);
    return output;
  }
}

Compile Your Contract with Lityc

lityc --bin-runtime Reverse.lity
======= ./Reverse.lity:ReverseContract =======
Binary of the runtime part:
608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063064767aa14610046575b600080fd5b34801561005257600080fd5b506100ad600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610128565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100ed5780820151818401526020810190506100d2565b50505050905090810190601f16801561011a5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0400000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528480516020019081601f0160209004602002604051908101604052905b6020831015156101fa57805182526020820191506020810190506020830392506101d5565b6001836020036101000a0d801982511681845116808217855250505050505080604051819003602090039052907f7265766572736500000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a723058208ce7aeccf2adc85557f879e3ac6ba2ca85fc018e77b351a8a424a32b40808d3f0029
lityc --abi Reverse.lity
======= ./Reverse.lity:ReverseContract =======
Contract JSON ABI
[{"constant":false,"inputs":[{"name":"input","type":"string"}],"name":"reverse","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]

Test Locally

Get our EVM from here <https://github.com/CyberMiles/go-ethereum>.

Run with ABCDE as input to your contract.

evm --code 608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063064767aa14610046575b600080fd5b34801561005257600080fd5b506100ad600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610128565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100ed5780820151818401526020810190506100d2565b50505050905090810190601f16801561011a5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0400000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528480516020019081601f0160209004602002604051908101604052905b6020831015156101fa57805182526020820191506020810190506020830392506101d5565b6001836020036101000a0d801982511681845116808217855250505050505080604051819003602090039052907f7265766572736500000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a723058208ce7aeccf2adc85557f879e3ac6ba2ca85fc018e77b351a8a424a32b40808d3f0029 --input 064767aa000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000054142434445000000000000000000000000000000000000000000000000000000 --statdump run
evm execution time: 19.432062ms
heap objects:       17981
allocations:        2648592
total allocations:  2648592
GC calls:           0
Gas used:           1329

0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000054544434241000000000000000000000000000000000000000000000000000000

According to the ABI of Ethereum contracts, the output could be decode as string EDCBA.

0000000000000000000000000000000000000000000000000000000000000020    # offset to string
0000000000000000000000000000000000000000000000000000000000000005    # string length
4544434241000000000000000000000000000000000000000000000000000000    # string "EDCBA"