Epoch node API - contract create endpoint


#1

Hi everyone,

I am developing Java based platform which has to communicate with Epoch node running locally. I managed to get localnet (3 nodes) up and running and I can curl API endpoints as expected. Now I’m trying to deploy smart contract from Java. Now if I’m not mistaken, in order to do that I have to generate contract creation transaction, sign it (ed25519) and then POST it to /transactions endpoint. Before making those requests using Java, I wanted to test few API endpoints manually (using curl or any similar tool) and check what JSON models I have to use in request body and also what responses do I get. I have found api documentation here and I’m trying to make request on /debug/contracts/create but I don’t know exactly how to format all the fields in body of this request. Are there any examples of real request/response data somewhere?

Thanks for any help you can provide.


#2

Hi Filip,

Here is more documentation about the Epoch API: https://github.com/aeternity/protocol/tree/master/epoch/api

We don’t have a Java SDK but it might be helpful to look at the python, javascript or go SDKs to see how they do it.



Hope this helps,

John


#3

Thanks John. Resources were helpful and resolved some of my issues. I am still confused about one thing which I cannot find answer to. There are two fields in /debug/contracts/create request: “call_data” and “code”. (as can be seen in this link to apidoc) They are of type byte array. I have few questions regarding these params.

In the case of “call_data” I assume those are constructor values for smart contract. How do I encode these? How to encode empty constructor? And what in case of solidity contract?

For “code” param, I found on docs you linked that its value type is base58 encoded bytecode of compiled smart contract. So I tried exactly that, but with Ethereum bytecode. I compiled Solidity smart contract, base58 encoded its bytecode and put “cb_” prefix on encoded string. I also adjusted “vm_version” field to integer value 2 since my bytecode is actually Solidity contract to be executed on AEVM (according to documentation here). But still I get error response when making request: {“reason”:“Not byte array: code”} . Something is wrong with my encoding but I don’t know exactly what. I encode bytecode here.

I know the questions are specific but any info regarding these two params, or “cb_xxxx…” value type would be very valuable for me, I’m having no progress with this for some time now.


#4

Hi there filip,

Have you read https://github.com/aeternity/protocol/blob/master/epoch/api/contract_api_usage.md which explains these calls in some detail?

There are only Sophia contracts on æternity. I have not tried to deploy ethereum bytecode from Soldity contracts to æternity, and have no idea if it works. https://contracts.aepps.com/ will compile and deploy Sophia code for you, have you tried it?

Let me know how you get on.

Best,

John


#5

One more thing–you may be able to use the Swagger interface definition at sdk-edgenet.aepps.com/api with something like swagger-codegen (https://swagger.io/tools/swagger-codegen/) to generate the access code. I had bad experiences with swagger-codegen and Rust, but it may work better for Java.

John