aqua-playground/src/index.ts

31 lines
959 B
TypeScript
Raw Normal View History

2021-04-12 02:07:18 +03:00
#!/usr/bin/env node
2021-04-15 11:51:02 +03:00
import {createClient, registerServiceFunction} from "@fluencelabs/fluence";
2021-06-03 17:27:32 +03:00
import {krasnodar} from "@fluencelabs/fluence-network-environment";
2021-05-26 18:24:45 +03:00
import {helloWorld} from "./compiled/examples/helloWorld";
2021-04-12 02:07:18 +03:00
const main = async () => {
// each compiled aqua function require a connected client
2021-06-03 17:27:32 +03:00
const client = await createClient(krasnodar[0]);
// example to how register a local service
// it could be used in aqua code as follows
// service StringExtra("service-id"):
// addNameToHello: string -> string
// see more in helloWorld.aqua
registerServiceFunction(client, "service-id", "addNameToHello", (args: any[], _) => {
return `Hello, ${args[0]}!`
})
// call an aqua function thet presented in ../aqua/helloWorld.aqua
const result = await helloWorld(client, "NAME");
console.log(result)
2021-04-28 20:16:27 +03:00
process.exit(0)
2021-04-12 02:07:18 +03:00
};
2021-04-28 03:26:26 +03:00
main().catch((err) => {
console.log(err)
process.exit(1)
2021-04-28 03:26:26 +03:00
})