[{"data":1,"prerenderedAt":783},["ShallowReactive",2],{"doc:docs_en:\u002Fdocs\u002F02-developer-dapp":3,"doc-nav:docs_en":766},{"id":4,"title":5,"body":6,"description":759,"extension":760,"meta":761,"navigation":330,"path":762,"seo":763,"stem":764,"__hash__":765},"docs_en\u002Fdocs\u002F02-developer-dapp.md","2. Guide for DApp developers",{"type":7,"value":8,"toc":743},"minimark",[9,13,23,74,79,84,102,105,113,116,155,161,165,211,218,222,236,240,258,268,298,383,386,405,419,425,431,438,442,506,510,514,533,537,577,582,586,635,644,648,658,662,739],[10,11,5],"h1",{"id":12},"_2-guide-for-dapp-developers",[14,15,16,17,22],"p",{},"Goal: get a Hydra Head running in a few minutes to test your DApp, then move to preprod. Finish ",[18,19,21],"a",{"href":20},"01-chuan-bi-may","1. Prepare your machine"," first.",[24,25,26,42],"table",{},[27,28,29],"thead",{},[30,31,32,36,39],"tr",{},[33,34,35],"th",{},"Path",[33,37,38],{},"When to use",[33,40,41],{},"What you need",[43,44,45,60],"tbody",{},[30,46,47,54,57],{},[48,49,50],"td",{},[18,51,53],{"href":52},"#a-offline-head-on-your-own-machine","A. Offline on your own machine",[48,55,56],{},"Test L2 transaction logic, Plutus scripts, DApp UI",[48,58,59],{},"Docker, Node.js. No funds, no credentials",[30,61,62,68,71],{},[48,63,64],{},[18,65,67],{"href":66},"#b-head-on-preprod-with-blockfrost","B. On preprod",[48,69,70],{},"Test the real L1 flow: open, deposit, close, fanout",[48,72,73],{},"Blockfrost project id, test ADA from the faucet",[75,76,78],"h2",{"id":77},"a-offline-head-on-your-own-machine","A. Offline head on your own machine",[80,81,83],"h3",{"id":82},"a1-run-hexcore-and-complete-first-time-setup","A1. Run Hexcore and complete first-time setup",[85,86,91],"pre",{"className":87,"code":88,"language":89,"meta":90,"style":90},"language-bash shiki shiki-themes github-light github-dark","hexcore\n","bash","",[92,93,94],"code",{"__ignoreMap":90},[95,96,99],"span",{"class":97,"line":98},"line",1,[95,100,88],{"class":101},"sScJk",[14,103,104],{},"The first time, the terminal prints a setup link with a one-time token:",[85,106,111],{"className":107,"code":109,"language":110},[108],"language-text","Hexcore is not configured yet. Open this link to finish setup:\n  http:\u002F\u002Flocalhost:4000\u002Fsetup?token=…\n","text",[92,112,109],{"__ignoreMap":90},[14,114,115],{},"Open the link and answer three questions:",[117,118,119,131,141],"ol",{},[120,121,122,126,127,130],"li",{},[123,124,125],"strong",{},"Network",": choose ",[92,128,129],{},"preprod"," (changeable later).",[120,132,133,136,137,140],{},[123,134,135],{},"How do heads connect to the chain?"," Choose ",[123,138,139],{},"Offline","; skip the credential.",[120,142,143,146,147,150,151,154],{},[123,144,145],{},"Admin account",": a password of at least 8 characters, or leave it empty and Hexcore generates one. A generated password is shown ",[123,148,149],{},"only once",", so save it immediately; if you lose it, use ",[92,152,153],{},"hexcore password",".",[14,156,157,158,154],{},"Everything can be changed later in ",[123,159,160],{},"Settings",[80,162,164],{"id":163},"a2-create-a-head","A2. Create a head",[117,166,167,173,182,193,205],{},[120,168,169,170,154],{},"Click ",[123,171,172],{},"Create a Hydra Head",[120,174,175,178,179,154],{},[123,176,177],{},"Kind of head",": ",[123,180,181],{},"Single machine",[120,183,184,185,188,189,192],{},"Enter a ",[123,186,187],{},"Name"," and the number of ",[123,190,191],{},"Nodes"," (up to 5; 1 is enough to try things, 2–3 to test several signers).",[120,194,195,178,198,201,202,154],{},[123,196,197],{},"Chain backend",[123,199,200],{},"Offline — no layer 1",". hydra-node version: keep ",[123,203,204],{},"2.4.2",[120,206,169,207,210],{},[123,208,209],{},"Create head",". Hexcore generates the Hydra and Cardano keys for each node.",[14,212,213,214,217],{},"Each node is seeded with ",[123,215,216],{},"20,000 ADA"," in the starting UTxO by default, which exists only inside this head; use the initial UTxO section of the form to write your own.",[80,219,221],{"id":220},"a3-start","A3. Start",[14,223,169,224,227,228,231,232,235],{},[123,225,226],{},"Start",". The first time it pulls an image of about 200 MB; an offline head ",[123,229,230],{},"opens immediately"," once the nodes are up. If it fails, check the ",[123,233,234],{},"Container log"," tab.",[80,237,239],{"id":238},"a4-send-commands-to-a-node","A4. Send commands to a node",[14,241,242,245,246,249,250,253,254,257],{},[123,243,244],{},"Console in the UI."," Head page → pick a node → ",[123,247,248],{},"Console",". Command templates only load into the editor for you to edit; ",[92,251,252],{},"Close"," and ",[92,255,256],{},"SafeClose"," ask for confirmation.",[14,259,260,263,264,267],{},[123,261,262],{},"From your code."," In the same panel, open the ",[123,265,266],{},"Connect"," tab:",[117,269,270,282],{},[120,271,272,275,276,279,280,154],{},[123,273,274],{},"Create token"," (give it a label). The ",[92,277,278],{},"hxn_…"," token is shown ",[123,281,149],{},[120,283,284,285,288,289,297],{},"Copy the ",[123,286,287],{},"WebSocket URL"," and the sample code, for example with ",[18,290,294],{"href":291,"rel":292},"https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@hydra-sdk\u002Fbridge",[293],"nofollow",[92,295,296],{},"@hydra-sdk\u002Fbridge",":",[85,299,303],{"className":300,"code":301,"language":302,"meta":90,"style":90},"language-ts shiki shiki-themes github-light github-dark","import { HydraBridge } from '@hydra-sdk\u002Fbridge';\n\nconst bridge = new HydraBridge({\n    url: 'ws:\u002F\u002Flocalhost:4000\u002Fapi\u002Fheads\u002F1\u002Fnodes\u002F0\u002Fsocket?X-Api-Key=hxn_…',\n    autoReconnect: true,\n});\n","ts",[92,304,305,325,332,354,366,377],{"__ignoreMap":90},[95,306,307,311,315,318,322],{"class":97,"line":98},[95,308,310],{"class":309},"szBVR","import",[95,312,314],{"class":313},"sVt8B"," { HydraBridge } ",[95,316,317],{"class":309},"from",[95,319,321],{"class":320},"sZZnC"," '@hydra-sdk\u002Fbridge'",[95,323,324],{"class":313},";\n",[95,326,328],{"class":97,"line":327},2,[95,329,331],{"emptyLinePlaceholder":330},true,"\n",[95,333,335,338,342,345,348,351],{"class":97,"line":334},3,[95,336,337],{"class":309},"const",[95,339,341],{"class":340},"sj4cs"," bridge",[95,343,344],{"class":309}," =",[95,346,347],{"class":309}," new",[95,349,350],{"class":101}," HydraBridge",[95,352,353],{"class":313},"({\n",[95,355,357,360,363],{"class":97,"line":356},4,[95,358,359],{"class":313},"    url: ",[95,361,362],{"class":320},"'ws:\u002F\u002Flocalhost:4000\u002Fapi\u002Fheads\u002F1\u002Fnodes\u002F0\u002Fsocket?X-Api-Key=hxn_…'",[95,364,365],{"class":313},",\n",[95,367,369,372,375],{"class":97,"line":368},5,[95,370,371],{"class":313},"    autoReconnect: ",[95,373,374],{"class":340},"true",[95,376,365],{"class":313},[95,378,380],{"class":97,"line":379},6,[95,381,382],{"class":313},"});\n",[14,384,385],{},"The node's HTTP API goes through the same proxy, for example to read the UTxO:",[85,387,389],{"className":87,"code":388,"language":89,"meta":90,"style":90},"curl -H \"X-Api-Key: hxn_…\" http:\u002F\u002Flocalhost:4000\u002Fapi\u002Fheads\u002F1\u002Fnodes\u002F0\u002Fsocket\u002Fsnapshot\u002Futxo\n",[92,390,391],{"__ignoreMap":90},[95,392,393,396,399,402],{"class":97,"line":98},[95,394,395],{"class":101},"curl",[95,397,398],{"class":340}," -H",[95,400,401],{"class":320}," \"X-Api-Key: hxn_…\"",[95,403,404],{"class":320}," http:\u002F\u002Flocalhost:4000\u002Fapi\u002Fheads\u002F1\u002Fnodes\u002F0\u002Fsocket\u002Fsnapshot\u002Futxo\n",[14,406,407,410,411,414,415,418],{},[92,408,409],{},"1"," is the head number, ",[92,412,413],{},"0"," is the node index. A token only opens the nodes of ",[123,416,417],{},"one"," head; revoking it closes the connections using it immediately.",[14,420,421,424],{},[123,422,423],{},"Keys for signing L2 transactions."," Each node's Cardano key is at:",[85,426,429],{"className":427,"code":428,"language":110},[108],"~\u002F.hexcore\u002Fheads\u002Fhead-\u003Cid>\u002Fkeys\u002Fn\u003Cindex>.cardano.sk\n",[92,430,428],{"__ignoreMap":90},[14,432,433,434,437],{},"Use it to sign ",[92,435,436],{},"NewTx",". On an offline head the key holds no real money; on preprod it is the real key of a funded address, so keep it secret.",[80,439,441],{"id":440},"a5-start-over","A5. Start over",[24,443,444,454],{},[27,445,446],{},[30,447,448,451],{},[33,449,450],{},"Action",[33,452,453],{},"Result",[43,455,456,466,476,486,496],{},[30,457,458,463],{},[48,459,460],{},[123,461,462],{},"Reset",[48,464,465],{},"Wipes persistence; an offline head returns to its starting UTxO",[30,467,468,473],{},[48,469,470],{},[123,471,472],{},"Edit",[48,474,475],{},"Only if the head never ran or failed to start; otherwise Reset first",[30,477,478,483],{},[48,479,480],{},[123,481,482],{},"Stop",[48,484,485],{},"Removes containers, keeps keys and state",[30,487,488,493],{},[48,489,490],{},[123,491,492],{},"Delete",[48,494,495],{},"Deletes the head, containers and state",[30,497,498,503],{},[48,499,500],{},[92,501,502],{},"hexcore clean",[48,504,505],{},"Deletes every head and container, keeps keys",[75,507,509],{"id":508},"b-head-on-preprod-with-blockfrost","B. Head on preprod with Blockfrost",[80,511,513],{"id":512},"b1-get-a-blockfrost-project-id","B1. Get a Blockfrost project id",[14,515,516,517,522,523,526,527,529,530,532],{},"Create a free project at ",[18,518,521],{"href":519,"rel":520},"https:\u002F\u002Fblockfrost.io",[293],"blockfrost.io"," and choose ",[123,524,525],{},"Cardano preprod",". The project id must start with ",[92,528,129],{},": a key for another network gives no error but creates a head that never sees its own transactions. Enter the key under ",[123,531,160],{}," → Blockfrost, or per head\u002Fnode on the create form.",[80,534,536],{"id":535},"b2-create-the-head-and-fund-the-nodes","B2. Create the head and fund the nodes",[117,538,539,559,570],{},[120,540,541,543,544,546,547,543,549,178,551,554,555,543,557,154],{},[123,542,172],{}," → ",[123,545,181],{}," → set ",[123,548,191],{},[123,550,197],{},[123,552,553],{},"Blockfrost"," → hydra-node ",[123,556,204],{},[123,558,209],{},[120,560,561,562,565,566,569],{},"The head page lists each node's preprod address. Click ",[123,563,564],{},"Open the faucet"," and request test ADA for ",[123,567,568],{},"each"," address (it pays L1 transaction fees).",[120,571,572,573,576],{},"If you already have a funded address, choose ",[123,574,575],{},"Use existing Cardano payment keys"," and paste its signing key. Extended BIP32 keys are rejected: hydra-node needs a plain payment key.",[14,578,579,581],{},[123,580,226],{}," is blocked when a node has no funds; if the balance cannot be read the button stays enabled, so check it yourself first.",[80,583,585],{"id":584},"b3-start-open-the-head-move-funds-in","B3. Start, open the head, move funds in",[117,587,588,593,603,619,622],{},[120,589,590,592],{},[123,591,226],{}," (slower than an offline head: Blockfrost lags the tip by 50–80 seconds).",[120,594,595,596,598,599,602],{},"Once the nodes are running, open a node's ",[123,597,248],{}," and send ",[92,600,601],{},"Init",". With hydra-node 2.x the head opens as soon as the transaction is confirmed on L1.",[120,604,605,606,609,610,613,614,154],{},"Move funds in with a ",[123,607,608],{},"deposit",": call ",[92,611,612],{},"POST \u002Fcommit"," on the node's HTTP API (through the proxy, with an access token), sign the returned transaction with the wallet that owns the UTxO, then submit it to L1. See the ",[18,615,618],{"href":616,"rel":617},"https:\u002F\u002Fhydra.family\u002Fhead-protocol\u002F",[293],"Hydra documentation",[120,620,621],{},"Test your DApp as in path A.",[120,623,624,625,627,628,630,631,634],{},"To finish: send ",[92,626,252],{}," (or ",[92,629,256],{},"), wait for the contestation period to end, then send ",[92,632,633],{},"Fanout"," to return the UTxO to L1.",[14,636,637,638,643],{},"Warning: a Blockfrost head can crash-loop on a token with an empty asset name (",[18,639,642],{"href":640,"rel":641},"https:\u002F\u002Fgithub.com\u002Fcardano-scaling\u002Fhydra\u002Fissues\u002F2923",[293],"hydra#2923","); a DApp using such tokens should choose cardano-node.",[80,645,647],{"id":646},"b4-use-cardano-node-instead-of-blockfrost","B4. Use cardano-node instead of Blockfrost",[14,649,650,651,653,654,657],{},"If you already run a synced preprod cardano-node on the same machine: ",[123,652,160],{}," → cardano-node socket → ",[123,655,656],{},"Find socket",". Hexcore scans and reports which socket answers on which network; a socket owned by another user (such as root in Docker) still works, and the screen explains how to grant access.",[75,659,661],{"id":660},"c-development-tips","C. Development tips",[663,664,665,688,694,708,714,723],"ul",{},[120,666,667,178,670,673,674,673,677,673,680,683,684,687],{},[123,668,669],{},"Run in the background",[92,671,672],{},"hexcore start --detach",", ",[92,675,676],{},"hexcore status",[92,678,679],{},"hexcore logs -f",[92,681,682],{},"hexcore stop"," (heads keep running). On macOS, ",[92,685,686],{},"hexcore service install"," registers launchd to start on login.",[120,689,690,693],{},[123,691,692],{},"Several hydra-node versions side by side",": each head pins its own image, so you can compare 2.4.1 and 2.4.2; the form also accepts any image.",[120,695,696,699,700,703,704,707],{},[123,697,698],{},"Protocol parameters"," are editable on the create form; ",[123,701,702],{},"Fetch latest"," reads the newest values while keeping your edits. The ",[123,705,706],{},"Resources"," tab measures CPU and RAM of the nodes.",[120,709,710,713],{},[123,711,712],{},"Share read-only"," (Connect tab): anyone can watch frames without a token but cannot send commands.",[120,715,716,719,720,154],{},[123,717,718],{},"Automation",": every action has an HTTP API, documented at ",[92,721,722],{},"http:\u002F\u002Flocalhost:4000\u002Fapi-docs",[120,724,725,728,729,732,733,738],{},[123,726,727],{},"Do not run two Hexcores on the same Docker daemon"," unless you must: container names (",[92,730,731],{},"hexcore-h1-n0","…) can collide between two installs (",[18,734,737],{"href":735,"rel":736},"https:\u002F\u002Fgithub.com\u002FVtechcom\u002Fhexcore-v2\u002Fissues\u002F6",[293],"#6",").",[740,741,742],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":90,"searchDepth":327,"depth":327,"links":744},[745,752,758],{"id":77,"depth":327,"text":78,"children":746},[747,748,749,750,751],{"id":82,"depth":334,"text":83},{"id":163,"depth":334,"text":164},{"id":220,"depth":334,"text":221},{"id":238,"depth":334,"text":239},{"id":440,"depth":334,"text":441},{"id":508,"depth":327,"text":509,"children":753},[754,755,756,757],{"id":512,"depth":334,"text":513},{"id":535,"depth":334,"text":536},{"id":584,"depth":334,"text":585},{"id":646,"depth":334,"text":647},{"id":660,"depth":327,"text":661},"Goal: get a Hydra Head running in a few minutes to test your DApp, then move to preprod. Finish 1. Prepare your machine first.","md",{},"\u002Fdocs\u002F02-developer-dapp",{"title":5,"description":759},"docs\u002F02-developer-dapp","4_xSIUvFqDpdTnoh42ENQTuH9_IDmUDveoMX228ycdA",[767,770,771,774,777,780],{"path":768,"title":769},"\u002Fdocs\u002F01-chuan-bi-may","1. Prepare your machine and install the Hexcore CLI",{"path":762,"title":5},{"path":772,"title":773},"\u002Fdocs\u002F03-cai-tren-server","3. Install Hexcore on a server (Ubuntu, Debian, RHEL family)",{"path":775,"title":776},"\u002Fdocs\u002F04-provider-trust-center","4. Guide for providers joining Hydra Trust Center",{"path":778,"title":779},"\u002Fdocs\u002F05-xu-ly-su-co","5. Troubleshooting",{"path":781,"title":782},"\u002Fdocs\u002Freadme","Hexcore v2 user guide",1795426328408]