Tutorial Hints

From mojo_puzzler
Jump to navigation Jump to search

From the document:

How to communicate between coins using announcements

https://docs.google.com/document/d/19KM73gW_Klyk477Ux3Tf5DcKzkWhlsq84e1OiVaVZp4/edit

Three basic steps

  1. Setup and seed the trigger coin
  2. Setup and seed the triggerd coin
  3. Create and execute the spend bundle


Step 1

  • Create new directory "coin announcement" and add a blank text file to use as a scratch pad(puzzle hashes for repetitive use and debugging etc).
  • Create file trigger.clvm using the following code from the tutorial:
(mod (mess new_puzhash amount)
    (defconstant CREATE_COIN 51)
    (defconstant CREATE_COIN_ANNOUNCEMENT 60)
 
    (list 
        (list CREATE_COIN new_puzhash amount)
        (list CREATE_COIN_ANNOUNCEMENT (sha256 mess)))
    )
)
  • Output a puzzle hash for itcdv clsp treehash trigger.clvm. Send 1 mojo to seed the trigger coinchia wallet send -a 0.000000000001 -t xch123456aedcfb98765aaaaa11111111.

Step 2

  • Create file triggerd.clvm using the following code from the tutorial:
(mod (sign_coin_id new_puzhash amount)
   (defconstant CREATE_COIN 51)
   (defconstant ASSERT_COIN_ANNOUNCEMENT 61)

   (list 
       (list CREATE_COIN new_puzhash amount) 
       (list ASSERT_COIN_ANNOUNCEMENT (sha256 sign_coin_id (q . 0x2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824)))
   )
)
  • Output a puzzle hash for it. Send 1 mojo to seed the triggerd coin.

Step 3

  • Create a file spend_bundle.json. Copy and paste the spend_bundle json code from the tutorial. NOTE: change "coin_solutions" to "coin_spends" to avoid warning that would occur at push_tx.
  • Update spend_bundle.json file: the first and second coins' amount, parent_coin_info, and puzzle_hash based on the two coins you earlier seeded.
  • Create serialized puzzle_reveal from trigger.clvm and update spend_bundle.json file with that value. HINT: cdv clsp build trigger.clvm and look into the resulting dot hex file.
  • Create a file for the trigger coin solution tsolution.clvm using the following code modified from the tutorial. NOTE: you must put your own wallet's puzzle hash:

(q . (hello 0x656214f18f80a85a30f97cafa0fdfd29578d5e8030316b21e36552f9172c49d1 1)). Create serialized solution for tsolution.clvm and update spend_bundle.json file with that value.

  • Create serialized puzzle_reveal for triggerd.clvm and update spend_bundle.json file with that value. HINT: cdv clsp build triggerd.clvm and look into the resulting dot hex file.
  • Create a file for the triggerd coin solution tsolutiond.clvm using the following code modified from the tutorial. NOTE: you must put ***valid coin ID of the trigger coin you created*** and your own wallet's puzzle hash):

(q . (0x7275ff0dc3007d5b87b2ab06388d40a6577393bae214d24324bf3c9179273a9a 0x656214f18f80a85a30f97cafa0fdfd29578d5e8030316b21e36552f9172c49d1 1)) Create serialized solution for tsolution.clvm and update spend_bundle.json file with that value.

  • Attempt to spend the coins in unison with cdv rpc pushtx ./spend_bundle.json. The response you are looking for is "{'status': 'SUCCESS', 'success': True}" and you can watch the coins incoming into your wallet to verify success.
  • If it fails try debugging with cdv inspect spendbundles ./spend_bundle.json -db