cdc
Creates a template function
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.cdc(head, rest)
Or import directly the specific function:
_10import { cdc } from "@onflow/sdk"_10_10cdc(head, rest)
Usage
_30import { template } from "@onflow/util-template"_30_30// String template_30const simpleTemplate = template("Hello, World!");_30console.log(simpleTemplate()); // "Hello, World!"_30_30// Template literal with interpolation_30const name = "Alice";_30const greeting = template`Hello, ${name}!`;_30console.log(greeting()); // "Hello, Alice!"_30_30// Cadence script template_30const cadenceScript = template`_30 access(all) fun main(greeting: String): String {_30 return greeting.concat(", from Flow!")_30 }_30`;_30console.log(cadenceScript()); // The Cadence script as a string_30_30// Used with FCL for dynamic Cadence code_30import * as fcl from "@onflow/fcl";_30_30const contractAddress = "0x123456789abcdef0";_30const scriptTemplate = fcl.cadence`_30 import MyContract from ${contractAddress}_30_30 access(all) fun main(): String {_30 return MyContract.getMessage()_30 }_30`;
Parameters
head
- Type:
string | TemplateStringsArray | ((x?: unknown) => string)
- Description: - A string, template string array, or template function
rest
(optional)
- Type:
unknown[]
- Description: - The rest of the arguments
Returns
(x?: unknown) => string