Æpps update: Smart Contract Development


#1

Hey everyone,

Our latest æpps update is out and it explores smart contracts.

The post is dedicated specifically to smart contract developers - find out more about our smart contract language Sophia, how to acquire Testnet tokens and our contract web tool.

Best regards,
The AE Team


#2

I tried this, and while it generally works, I cannot seem to review a deployed contract’s address in the explorer?

I.e. when I deploy and get the message “Deployed, and mined at this address: <X>”, and then paste this into the input field at https://explorer.aepps.com/#/ which says “Explore Generation, Block, Address”, I get an error message “not a valid block hash/height or account public key”.

Also when I try to top-up the contract’s address this way at https://faucet.aepps.com, I get
“Something went wrong.
bad request”


#3

Hi there,

The blockchain explorer cannot currently show deployed contracts–we’ll add this in time. You can use the CLIs which are part of the SDKs to do this–pick your favourite of Javascript/Python/Go, install it and use the ‘aecli inspect …’ command to view the contract.

Let us know how you get on!

John


Where are smart contracts stored?
#4

Deploying contracts using https://contracts.aepps.com somehow doesn’t seem to work atm, it says

Deploy Errors:
Error: Giving up after 10 blocks mined

So I tried to compile locally (with the JS sdk) which however wants my private and public key configured in the environment:

goldmund:aepp-sdk-js babarr$ node bin/aecli.js contract compile "test.sophia"
Environment variables WALLET_PRIV and WALLET_PUB need to be set

Trying to find out their values throws an error because node.js can’t use ES6 modules:

goldmund:aepp-sdk-js babarr$ node bin/aecli.js crypto decrypt ~/aenode/generated_keys
/Users/babarr/devel/ae/aepp-sdk-js/bin/utils/index.js:18
import * as constant from './constant'
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/babarr/devel/ae/aepp-sdk-js/bin/aecli-crypto.js:23:15)

I tried using “–experimental-modules” but files using ES6 modules then still need to be named *.mjs, which they are not in the repo (just *.js). How is one supposed to run this?


Where are smart contracts stored?
#5

Hey @databu,
Have you tried to set those env variables?

set WALLET_PRIV=ed18d3d2494d29b43747bdfde3468a3f7b39b6a245bd90184da1520b757e6ca351d48c158960de4424e8409280270ba3be065a97b61c081f35ca7d2f5ff3955d

set WALLET_PUB=ak$d3FAaqGfMGsgGbGBfoJz8XrwnAuTqTBxzgDVBqapABM7nq8Xo

Run
printenv
command to check if they are stored correctly.

For windows set command is same. You can dump all variables with
set
command.


#6

Are those the keys for the account that https://contracts.aepps.com uses? Deploying via that site still doesn’t seem to work…

Therefore I wanted to find out my own private/public keys, but in the generated_keys directory in the wallet they’re only in binary form, which is why I tried to use the command line tools to get their ASCII representations, but ran into the problem I mentioned in my previous post.


#7

I finally got this to work using babel-node:

babel-node bin/aecli.js crypto decrypt ../../../aenode/generated_keys

Also note that the path to the key directory always seems to be interpreted as being relative, even when an absolute one is given.


#8

Hi everyone,

First of all apologies that things have been disorganised lately. We had to absorb a lot of changes from the core team, which made our release schedule totally out of sync, and this is the cause of the problems you’ve been having.

The WALLET_PRIV and WALLET_PUB and the ES6 problems should now be solved.

In general I would recommend that you continue to use the edgenet (what the develop branch of JS SDK connects to). We’ll have a faucet for that in the next days, if you want tokens right now, send me your pub key and I’ll transfer you more than you could ever need.

We’ll be getting a much better release schedule from now, and should avoid this confusion in the future.

Best, and thanks for the feedback, and for using our software,

John


#9

Quick update: there is now a faucet for edgenet, which should make life easier for everyone. It’s linked from the front page at https://dev.aepps.com/ or you can go to it directly at https://edge-faucet.aepps.com/


#10

Unfortunately the sdks seem to still only support v0.22.0. Where can I test deploying smart contracts right now? Things I tested so far, none of which works:

  1. https://contracts.aepps.com/ - Still “Error: Giving up after 10 blocks mined”
  2. Installed the JS sdk via npm i aeternity/aepp-sdk#develop to get the latest version, but apparently this still supports only epoch v.0.22.0? Trying to deploy a contract via node node_modules/.bin/aecli contract deploy keys/wallet lib/test.sophia asks for the password and then never returns.
  3. I tried running the local net via docker-compose from the epoch v0.24.0 source, here I sometimes (but not always) had to use the -f flag to disable the epoch version check (because v.0.24.0 is not supported, but why didn’t I get this error when connecting to edge net?). Otherwise same behaviour as in 2.
  4. I checked epoch v0.22.0 out instead and run it with docker-compose up --build, but it fails with this (pasting the output for node1 only, 2+3 are similar):

node1_1 | 22:22:03.581 [warning] Expected genesis block hash <<235,106,139,33,181,169,141,115,70,123,35,225,74,123,253,148,67,152,247,117,19,122,214,130,121,15,62,89,7,167,240,102>>, persisted genesis block hash <<164,155,168,139,1,162,198,95,94,114,171,5,249,144,16,111,35,229,207,192,11,155,254,174,251,31,198,113,53,253,34,132>>
node1_1 | 22:22:03.581 [error] Persisted chain has a different genesis block than the one being expected. Aborting
node1_1 | {“Kernel pid terminated”,application_controller,"{application_start_failure,aecore,{inconsistent_database,{aecore_app,start,[normal,[]]}}}"}
node1_1 | Kernel pid terminated (application_controller) ({application_start_failure,aecore,{inconsistent_database,{aecore_app,start,[normal,[]]}}})
epoch_node1_1 exited with code 1

Given all this, is it possible right now to test deploying a contract at all? If so, what’s the easiest/quickest way to do so?


#11

Nevermind point 4., I forgot to remove the previously persisted volumes. After I did this (docker-compose down -v) and rebuilt v0.22.0 with docker-compose up --build, I was finally able to deploy a contract:

node node_modules/.bin/aecli contract --host http://localhost:3002 deploy ./wallet lib/test.sophia
prompt: Enter your password:  ************

Contract was successfully deployed
Contract address________________________ ct_2onpm6EZqXpFNkXZiZrp9QD18djoeb2NQ9RRXDtRs5bF326SRQ
Transaction hash________________________ th_5cUdUhm2DQX18AxLav4zchN7QsJPXmDhUPwcr2SUY8J1PRwp2
Deploy descriptor_______________________ test.sophia.deploy.2idbLB1sKVJd9EUieKTR47kjZFPRfJVxX9WNmSanqoGHeJzjch.json

#12

@databu Great hearing that nr.4 worked! :slight_smile:

To give you some context:

develop branch of the JS SDK is on v0.22.0 of Epoch.
"version": "0.22.0-0.1.0-alpha.2" in the package.json means “Epoch v0.22.0” and “JS SDK v0.1.0” (related to that Epoch version).

For your point nr. 1: We will solve the problem next week, by releasing a new version for all of our SDKs and a new version of the “Contracts Aepp”.

For your point nr. 2: You can use Epoch 0.22.0 (or a local Node) by adding its host like: path/to/aecli.js -H https://sdk-edgenet.aepps.com [command] [command2] [options]

For your point nr. 3 and 4: We also have a docker-compose file in the root of the JS SDK as well. You can use that, and add a simple docker-compose.override.yml to expose ports like so:

version: "3"
services:
  node:
    ports:
      - 3013:3013
      - 3113:3113

and then maybe only run docker-compose up node, to avoid building the SDK.

This uses the TAG variable in the .env file, which always contain the version number, supported by the SDK branch/release you checkout.

Hope this helps, clearing out some doubts. Let us know if you have any more issues we can help you with :slight_smile: …and thanks for trying the product!


#13

Thank you @ricricucit, yes that clears some things up! I had misunderstood what edgenet is, I thought it’s composed of nodes running the latest version of Epoch, rather than the latest SDK-supported version. So if I understand correctly, simply running a v0.22.0 node and connecting to edgenet should work?
Anyway it was still worth the effort setting up the local test net. I’m using it in the context of an Æternity-based (and -sponsored, I might add) blockchain lecture, and the internet connection there is not always stable, so it’s good to be able to run things purely locally.


#14

I also tried this now, but the edge net seems to run v0.24.0 not the supported v.0.22.0:

goldmund:aelecture babarr$ ./node_modules/.bin/aecli -H https://sdk-edgenet.aepps.com account balance ./wallet3
prompt: Enter your password:  *********

Unsupported epoch version 0.24.0
goldmund:aelecture babarr$ 

#15

Yes, Edgenet is always there there to help us move towards the next release (supporting compatibility with latest Epoch, now 0.24.0).

We should release today, starting from this branch which already supports it. Sorry for the confusion, you should see a new release soon. :slight_smile:


#16

And just to add to this, when testnet becomes 0.24.x then this will be full-featured and stable for a while to come. We’ve had big problems realeasing, which are almost over. After that it ought to be easier to use the SDKs straight out of the box.


#17

Just a heads up @databu :

The JS SDK has been updated to Epoch 0.24.0 …and also: https://contracts.aepps.com/ :slight_smile:


#18

Yes, I was meanwhile able to test this successfully.


#19

However, when I compile the default “Identity” contract on https://contracts.aepps.com – which says it’s currently connecting to https://sdk-edgenet.aepps.com --, I get byte code

cb_8TfnaSmi7H…

But when I copy-paste it into a local file and compile this with the v24 SDK also on edge net: I get a different byte code:

bin/aecli.js contract --host https://sdk-edgenet.aepps.com compile ./test.sophia
Please provide KEY_PAIR for sign transaction
Contract bytecode:
cb_8TfnaSmi8…

Why is that? And how can one extract the compiler version from the byte code?


#20

Hi @databu, the following discovery comes from our colleague Nazar.

In the contract Aepp we send the code without the char \n at the end, while in the SDK we noticed we have a \n in the string, at the end. This is because of the default way fs works.

If you try to add a newline char (\n) in the contract aepp, you’ll end up having the same hash, in both places.

Actually: thank you for noticing this, we’re going to include a fix in the next release!