To-do tutorial questions

Hi All,

I’ve been crawling my way through the to-do tutorial for a few days now. I get stuck, search, post an issue here and move forward. I’m currently attempting to run the tests and the issue is my instance of Ae SDK cannot find the compiler. Searching around I found there is a compilerUrl property that is passed to the constructor/Ae function:


const ownerKeyPair = wallets[0];
		owner = await Ae({
			url: config.host,
			internalUrl: config.internalHost,
			keypair: ownerKeyPair,
			nativeMode: true,
            networkId: 'ae_devnet',
            compilerUrl: config.compilerUrl
		});

When I run the tests i get the following error:


Error: Compiler not defined
      at Object.isInit (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:148596)
      at Object.<anonymous> (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:146072)
      at u (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:16427)
      at Generator._invoke (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:16215)
      at Generator.t.(anonymous function) [as next] (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:16849)
      at n (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:2194)
      at c (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:2404)
      at D:\aeternity\to-do-contract\node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:2463
      at new Promise (<anonymous>)
      at Object.<anonymous> (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:2345)

Any help is appreciated.

In the ‘ToDo Manager Tutorial issues’ post i see some questions regarding the importance of this tutorial. I for one think this tutorial is extremely important as it covers all the basics of what’s needed to build an actual daepp. It (if it was up to date) could cover a lot of the missing documentation by communicating how all the pieces (node, compiler, sdk) fit together to actually create something on Aeternity. Once I get this going I’d be happy to share the results, make a PR of changes.

Also, I’ve requested access to the dev chat. What about a discord channel? Are devs hanging out somewhere else?

Hey @rwfresh, @emin.chain would be able to help you.

Hi @rwfresh
once you run aeproject node, the ‘compiler’ will be available and should not throw an error.

I am running aeproject node. The node is running.

$ curl http://127.0.0.1:3001/v2/status
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   589  100   589    0     0  19000      0 --:--:-- --:--:-- --:--:-- 19000{"difficulty":204289793,"genesis_key_block_hash":"kh_2KhFJSdz1BwrvEWe9fFBRBpWoweoaZuTiYLWwUPh21ptuDE8UQ","listening":true,"network_id":"ae_devnet","node_revision":"9e251f87532934df535f315c265ac9887fd6fc6a","node_version":"4.1.0","peer_count":2,"peer_pubkey":"pp_239LxNMPw4jyFsiwXbufz5YjyCpqJBhr92BkZaxDrjtvwgTfWR","pending_transactions_count":0,"protocols":[{"effective_at_height":1,"version":3},{"effective_at_height":0,"version":1}],"solutions":0,"sync_progress":100.0,"syncing":false,"top_block_height":17578,"top_key_block_hash":"kh_2L45t7ZR3Ee15xMCud1FEBaXz3zDYSfbRvJLQBZsfseK4jzrwR"}

Following the to-do tutorial instantiation of Ae sdk object looks like this:

const config = { host: "http://localhost:3001/", internalHost: "http://localhost:3001/internal/", gas: 200000, ttl: 55 };

describe('ToDoManager Contract', () => {


let owner;
let contractSource

before(async () => {
    const ownerKeyPair = wallets[0];
    owner = await Ae({
        url: config.host,
        internalUrl: config.internalHost,
        keypair: ownerKeyPair,
        nativeMode: true,
        networkId: 'ae_devnet'
    });

});

This doesn’t work. I’ve tried changing the internal port to 3113. When I run the tests as per the tutorial using the above configuration I get the:

Error: Compiler not defined

I also tried explicitly setting the compiler to: compilerUrl: “https://compiler.aepps.com/” with the same result.

Any other ideas or insights? thanks!

@rwfresh did docker-compose.compiler.yml exists in your project folder? if not try with one of these compilers

docker run -d -p 3080:3080 aeternity/aesophia_http:v3.2.0
docker run -d -p 3080:3080 aeternity/aesophia_http:v4.0.0

well i initialized the project with aeproject init. And again, my node is running. I’m not in front of my development computer but I can check later today.

" if not try with one of these compilers"

How do i try? ie: what will my Ae() function call look like if I run a node in docker? What network will the above run on? local mock network?

Is there a curl request I can explicitly make to the node to check if there is a compiler running.

@rwfresh “Is there a curl request I can explicitly make to the node to check if there is a compiler running.” -> you make request to the compiler, not to the node http://localhost:3080/api or http://localhost:3080/version

so it’s definitely running

{"version":"3.2.0"}

What should my Ae init function params look like?

I am using the js SDK

owner = await Ae({
        url: "http://localhost:3001/",
        internalUrl: "http://localhost:3001/internal/",
        keypair: ownerKeyPair,  
        nativeMode: true,
        networkId: 'ae_devnet'
    });

What is the shape of the ownerKeyPair? It’s not apparent from the to-do tutorial.

Once I call the above I attempt to:

const compiledContract = await owner.contractCompile(contractSource, { // Compile it
			gas: 200000
		});

and then I get the error:

Error: Compiler not defined
      at Object.isInit (node_modules\@aeternity\aepp-sdk\dist\aepp-sdk.js:1:148596)

Should I pass http://localhost:3080/ into the Ae constructor?

thanks!

yes, you should.

client = await Ae({
            url: network.url,
            internalUrl,
            keypair: keypair,
            nativeMode: true,
            networkId: network.networkId,
            compilerUrl: network.compilerUrl
        })

Coming back to my main question after confirming my node is running and the compiler is there - Can you please show me an example of what this should look like, with actual values rather than parameters? This is where I am having problems.

client = await Ae({
            url: network.url, // what should this look like? https://127.0.0.1:3001 ???
            internalUrl, // what should this value be? 
            keypair: keypair, // what could this look like? { publickey??, privatekey??}
            nativeMode: true,
            networkId: network.networkId, // assuming in my case this should be "ae_devnet"
            compilerUrl: network.compilerUrl // what should this be? using http://127.0.0.1:3080 gives me the compiler not found error
        })

I hope it’s clear what I am looking for. Thanks!

Hi @rwfresh

const AeSDK = require('@aeternity/aepp-sdk');
const Universal = AeSDK.Universal;
const Node = AeSDK.Node;

// make sure this keyPair has enough amount
// or use key pair from funded ones
// public key: ak_fUq2NesPXcYZ1CcqBcGC3StpdnQw3iVxMA3YSeCNAwfN4myQk
// private key: 7c6e602a94f30e4ea7edabe4376314f69ba7eaa2f355ecedb339df847b6f0d80575f81ffb0a297b7725dc671da0b1769b1fc5cbe45385c7b5ad1fc2eaf1d609d
const keypair = {
        publicKey: 'PUBLIC_KEY',
        secretKey: 'SECRET_KEY'
    }

    let contractPath = './contracts/ExampleContract.aes'
    const contractSource = fs.readFileSync(contractPath, 'utf8');

    let network = {
        url: 'http://localhost:3001',
        internalUrl: 'http://localhost:3001/internal',
        networkId: "ae_devnet",
        compilerUrl: 'http://localhost:3080'
    }

    let node = await Node({
        url: network.url,
        internalUrl: network.internalUrl,
        forceCompatibility: true
    })

    let client = await Universal({
        nodes: [{
            name: 'ANY_NAME',
            instance: node
        }],
        accounts: [AeSDK.MemoryAccount({
            keypair
        })],
        nativeMode: true,
        networkId: network.networkId,
        compilerUrl: network.compilerUrl,
        forceCompatibility: true
    })

    let contractInstance = await client.getContractInstance(contractSource);
    let deployedContract = await contractInstance.deploy(); 

more info you can get from the sdk-js docs GitHub - aeternity/aepp-sdk-js: Javascript SDK for the æternity blockchain

Hi Aleksey, when I attempt to call a function on the successfully deployed contract I get the following error:

deployedContract.call is not a function

Looking Simple Sophia Contract Compiler and http://aeternity.com/documentation-hub/tutorials/build-to-do-list-aepp-1/ would lead me to believe I should be able to .call on the deployedContract object.

thanks!

Hi, @rwfresh
can you give me a link to your repo.

Hi @alekseytsekov.chain,

Trying to go through this with minimal available time so I really appreciate the help. I am going through the todo tutorial. I’ve put up the repo here: GitHub - rwfresh/aeternity-todo: sample aeternity todo daepp . Tests are failing: aeternity-todo/toDoManagerTests.js at master · rwfresh/aeternity-todo · GitHub . I’m sure it’s something stupid I’ve hastily overlooked.

Hi @rwfresh

when I clone your repo, there was a missing aeproject-lib => npm i aeproject-lib --save
and I refactored some of your code

// some code 
...
...
...
	describe('Interact with contract', () => {

		let contractInstance;

		beforeEach(async () => {
			contractSource = utils.readFileRelative('./contracts/ToDoManager.aes', "utf-8"); // ! this line was missing. you can read the file above first describe or in first before
			contractInstance = await owner.getContractInstance(contractSource); // contractSource was null
			
			// deploy returns tx info not contract instance
			await contractInstance.deploy();

            // console.log("DEPLOYED CONTRACT:", deployedContract);
		});

		describe('Contract functionality', () => {
			describe('Create a task', () => {
				it.only('should create a task successfully', async () => {
					//Arrange
					const taskName = 'Task A';

					//Act
					const addTaskResult = await contractInstance.call('add_to_do', [taskName]);

					console.log('addTaskResult')
					console.log(addTaskResult)

					// assert.isFulfilled(addTaskPromise, 'Could not call add_to_do');
					// const taskCreationResult = await addTaskPromise;

					//Assert
					// const taskCreationResultDecoded = await taskCreationResult.decode("string");
					// assert.equal(taskCreationResultDecoded.value, taskName)
				});

			});
...
...
...

Best,
Aleksey

Finally had some time to go through this again. Test are working now with the above and required changes to the sdk requests. Thanks!

2 Likes