Quick-start with Deku-C
In this 15-minute tutorial, we'll create our first DApp to Deku-C.
You'll learn how to:
- Write a simple smart contract in Ligo.
- Compile and deploy it to Deku-C
- Interact with the contract via
@marigold-dev/deku
Installing the Tools
You can run deploy the contract in-browser without installing any additional tools.
However, to follow along on along on the command line and to start developing your own contracts, you'll need to install the LIGO compiler - check the installation instructions for your platform. This tutorial requires version 0.53.0 or higher.
You'll also need to install the Deku CLI:
npm install -g @marigold-dev/deku-cli
See the Deku CLI Tutorial for more on using the CLI!
Our First Smart Contract
Let's write a simple counter, accepting the commands Increment
, Decrement
,
Reset
.
type storage = int;type parameter = ["Increment", int] | ["Decrement", int] | ["Reset"];type return_ = [list<operation>, storage];const main = (action: parameter, store: storage): return_ => {let storage = match(action, {Increment: (n) => store + n,Decrement: (n) => store - n,Reset: () => 0,});return [list([]), storage];};
Refer to the Ligo documentation for more on developing with Ligo, and don't hesitate to reach out!
Deploying Our Contract
We can originate our contract using @marigold-dev/deku
, a Deku-C client
written in Typescript package. The client depends on
Taquito for signing interactions with Deku chain.
Taquito provides options for using a variety of browser-based and hardware
wallets, but for convenience we'll use the in-memory signer.
import { DekuCClient } from "@marigold-dev/deku"import { fromMemorySigner } from "@marigold-dev/deku"import { InMemorySigner } from "@taquito/signer"const memory = new InMemorySigner("edsk3ym86W81aL2gfZ25WuWQrisJM5Vu8cEayCR6BGsRNgfRWos8mR");const dekuSigner = fromMemorySigner(memory);const dekuC = new DekuCClient({dekuRpc: "https://deku-canonical-vm0.deku-v1.marigold.dev/",ligoRpc: "https://ligo-deku-rpc.marigold.dev"dekuSigner,});
With a connection to Deku-C established, we're ready to deploy our contract! Try running the example.
In addition to using deku-toolkit
and/or command-line tools, you can
also develop Deku-C contract directly from your browser with the
LIGO Playground!
Interacting with our Contract
Once deployed, we can use the Deku-C client to query and subscribe to our contract's state, as well as invoke operations. In the live editor below, we've hard-coded the address of a contract on Deku-C, but you can replace it with the DK1 address of the contract you deployed above.