Building canisters…
Error: Failed while trying to build all canisters.
Caused by: Failed while trying to build all canisters.
The build step failed for canister ‘be2us-64aaa-aaaaa-qaabq-cai’ (Crowdfund_backend) with an embedded error: Failed to build Motoko canister ‘Crowdfund_backend’.: Failed to compile Motoko.: Failed to run ‘moc’.: The command ‘“/home/sazalo/.cache/dfinity/versions/0.18.0/moc” “/home/sazalo/Your-Charity/final_project/Crowdfund/src/Crowdfund_backend/main.mo” “-o” “/home/sazalo/Your-Charity/final_project/Crowdfund/.dfx/local/canisters/Crowdfund_backend/Crowdfund_backend.wasm” “-c” “–debug” “–idl” “–stable-types” “–public-metadata” “candid:service” “–public-metadata” “candid:args” “–actor-idl” “/home/sazalo/Your-Charity/final_project/Crowdfund/.dfx/local/canisters/idl/” “–actor-alias” “Crowdfund_backend” “be2us-64aaa-aaaaa-qaabq-cai” “–package” “base” “/home/sazalo/.cache/dfinity/versions/0.18.0/base”’ failed with exit status ‘exit status: 1’.
Stdout:
Stderr:
/home/sazalo/Your-Charity/final_project/Crowdfund/src/Crowdfund_backend/main.mo:6.29-6.30: syntax error [M0001], unexpected token ‘=’, expected one of token or sequence:
}
<typ_args>?
<exp(ob)>
; seplist(<dec_field>,)
|> <exp_bin(ob)>
or <exp_bin(ob)>
<exp(ob)>
implies <exp_bin(ob)>
<exp_bin(ob)>
.
: <typ_nobin>
→ <typ_nobin>
<exp_bin(ob)>
<exp(ob)>
and <exp_bin(ob)>
<exp_bin(ob)>
when i run the below code import Http “mo:base/Http”;
actor DonateFormHandler {
// Define the HTTP service
service : Http.Canister = Http.service;
// Define the endpoint to handle the donation form submission
public func donate(name : Text, amount : Nat, message : Text) : async Text {
// Convert the amount to Text for concatenation
let amountText = Nat.toText(amount);
// Process the donation here
// For demonstration purposes, let's just return a success message
return "Donation successful. Thank you, " # name # "! Amount: " # amountText;
}
// HTTP request handler for the "/donate" endpoint
public query func handleRequest(request : Http.Request) : async Http.Response {
switch (request.method) {
case Http.Method.POST:
switch (request.url.path) {
case [] : // Root path
// Parse form data
let name = request.body.get("name")?;
let amount = request.body.getNat("amount")?;
let message = request.body.get("message")?;
// Call the donate function with form data
let responseText = await donate(name, amount, message);
// Return a success response
return Http.Response.text(responseText);
default:
return Http.Response.notFound();
}
default:
return Http.Response.methodNotAllowed();
}
}
// Start the HTTP service
public func start() : async () {
await service.start(handleRequest, null);
}
};
// Entrypoint
public func main() : async () {
await DonateFormHandler.start();
};