Skip to content

Commit

Permalink
Merge pull request #1606 from demergent-labs/candid-path
Browse files Browse the repository at this point in the history
first pass at optional path
  • Loading branch information
lastmjs authored Feb 2, 2024
2 parents a83c2d8 + 280a77a commit 26ee3ce
Show file tree
Hide file tree
Showing 28 changed files with 4,910 additions and 303 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
"examples/func_types",
"examples/guard_functions",
"examples/heartbeat",
"examples/hello_world",
"examples/ic_api",
"examples/icrc",
"examples/imports",
Expand Down
18 changes: 3 additions & 15 deletions examples/async_await/src/async_await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { managementCanister } from 'azle/canisters/management';
export default Canister({
getRandomnessDirectly: update([], blob, async () => {
if (process.env.AZLE_TEST_FETCH === 'true') {
const response = await fetch(`icp://aaaaa-aa/raw_rand`, {
body: serialize({
candidPath: '/candid/management.did'
})
});
const response = await fetch(`icp://aaaaa-aa/raw_rand`);
const responseJson = await response.json();

return responseJson;
Expand All @@ -32,11 +28,7 @@ export default Canister({
}),
returnPromiseVoid: update([], Void, async () => {
if (process.env.AZLE_TEST_FETCH === 'true') {
await fetch(`icp://aaaaa-aa/raw_rand`, {
body: serialize({
candidPath: '/candid/management.did'
})
});
await fetch(`icp://aaaaa-aa/raw_rand`);
} else {
await ic.call(managementCanister.raw_rand);
}
Expand All @@ -57,11 +49,7 @@ async function getRandomnessLevel2(): Promise<blob> {

async function getRandomness(): Promise<blob> {
if (process.env.AZLE_TEST_FETCH === 'true') {
const response = await fetch(`icp://aaaaa-aa/raw_rand`, {
body: serialize({
candidPath: '/candid/management.did'
})
});
const response = await fetch(`icp://aaaaa-aa/raw_rand`);
const responseJson = await response.json();

return responseJson;
Expand Down
6 changes: 1 addition & 5 deletions examples/heartbeat/src/heartbeat_async/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export default Canister({

async function getRandomness(): Promise<Uint8Array> {
if (process.env.AZLE_TEST_FETCH === 'true') {
const response = await fetch(`icp://aaaaa-aa/raw_rand`, {
body: serialize({
candidPath: '/candid/management.did'
})
});
const response = await fetch(`icp://aaaaa-aa/raw_rand`);
const responseJson = await response.json();

return responseJson;
Expand Down
3 changes: 3 additions & 0 deletions examples/hello_world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.azle
.dfx
node_modules
56 changes: 56 additions & 0 deletions examples/hello_world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Azle Hello World

Azle helps you to build secure decentralized/replicated servers in TypeScript or JavaScript. The current replication factor is [13-40 times](https://dashboard.internetcomputer.org/subnets).

For more documentation please see [The Azle Book](https://demergent-labs.github.io/azle/).

## Installation

Run the following commands individually following the instructions in the comments:

```bash
npx azle new hello_world
cd hello_world

# Ubuntu build dependencies
sudo apt install clang
sudo apt install build-essential
sudo apt install libssl-dev
sudo apt install pkg-config

# Mac build dependencies
xcode-select --install
brew install llvm

# The dfx command line tools for managing ICP applications
DFX_VERSION=0.16.1 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
dfx start --clean --host 127.0.0.1:8000

# In a separate terminal in the hello_world directory
npm install
dfx deploy

# If you have problems deploying see https://demergent-labs.github.io/azle/deployment.html#common-deployment-issues

# Obtain your application's [canisterId]
dfx canister id backend

# View your frontend in a web browser at http://[canisterId].localhost:8000

# Communicate with your canister using any HTTP client library
curl http://[canisterId].localhost:8000/db
curl -X POST -H "Content-Type: application/json" -d "{ \"hello\": \"world\" }" http://[canisterId].localhost:8000/db/update
```

## Examples

There are many Azle examples in the [examples directory](bkyz2-fmaaa-aaaaa-qaaaq-cai). We recommend starting with the following:

- [apollo_server](https://github.com/demergent-labs/azle/tree/main/examples/apollo_server)
- [ethers](https://github.com/demergent-labs/azle/tree/main/examples/ethers)
- [express](https://github.com/demergent-labs/azle/tree/main/examples/express)
- [fs](https://github.com/demergent-labs/azle/tree/main/examples/fs)
- [hello_world](https://github.com/demergent-labs/azle/tree/main/examples/hello_world)
- [ic_evm_rpc](https://github.com/demergent-labs/azle/tree/main/examples/ic_evm_rpc)
- [sqlite](https://github.com/demergent-labs/azle/tree/main/examples/sqlite)
- [web_assembly](https://github.com/demergent-labs/azle/tree/main/examples/web_assembly)
14 changes: 14 additions & 0 deletions examples/hello_world/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"canisters": {
"backend": {
"type": "custom",
"main": "src/backend/index.ts",
"candid": "src/backend/index.did",
"build": "npx azle backend",
"wasm": ".azle/backend/backend.wasm",
"gzip": true,
"assets": [["src/frontend/dist", "dist"]],
"build_assets": "npm run build"
}
}
}
9 changes: 9 additions & 0 deletions examples/hello_world/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_CANISTER_ORIGIN: string | undefined;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
Loading

0 comments on commit 26ee3ce

Please sign in to comment.