## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE ) ## ----setup-------------------------------------------------------------------- # library(multichainr) # # # Set the path to your MultiChain binaries # mc_set_path(Sys.getenv("MULTICHAIN_PATH")) ## ----init--------------------------------------------------------------------- # chain_name <- "asset_demo_chain" # # # Create the blockchain configuration # mc_node_init(chain_name) # # # Start the node in the background # mc_node_start(chain_name) # # # Allow the node a few seconds to initialize the wallet and network # Sys.sleep(3) # # # Connect to the local node # config <- mc_get_config(chain_name) # conn <- mc_connect(config) ## ----addresses---------------------------------------------------------------- # # Generate new wallet addresses # issuer_addr <- mc_get_new_address(conn) # recipient_addr <- mc_get_new_address(conn) # # # Grant 'issue' and 'send' permissions to the issuer # mc_grant(conn, issuer_addr, "issue,send,receive") # # # Grant 'receive' permissions to the recipient # mc_grant(conn, recipient_addr, "receive") ## ----fungible----------------------------------------------------------------- # # Define an asset named 'gold' with 2 decimal places (units = 0.01) # gold_params <- list(name = "gold", open = TRUE) # # # Initial issuance of 1,000 units # mc_issue(conn, issuer_addr, gold_params, quantity = 1000, units = 0.01) # # # Increase the total supply by an additional 500 units # mc_issue_more(conn, issuer_addr, "gold", 500) # # # Verify the balance of the issuer # issuer_balances <- mc_get_address_balances(conn, issuer_addr) # print(issuer_balances) ## ----nft_parent--------------------------------------------------------------- # art_params <- list( # name = "art", # fungible = FALSE, # open = TRUE # ) # # # Issue the parent container # mc_issue(conn, address = issuer_addr, name = art_params, quantity = 0, units = 1) ## ----issue_tokens------------------------------------------------------------- # # Issue a unique token "painting_001" with specific metadata # mc_issue_token(conn, # address = issuer_addr, # asset = "art", # token = "painting_001", # quantity = 1, # token_details = list(artist = "Leonardo da Vinci", year = 1503)) # # # Retrieve specific token metadata # token_info <- mc_get_token_info(conn, "art", "painting_001") # print(token_info) ## ----transfers---------------------------------------------------------------- # # 1. Send 100 units of fungible 'gold' # mc_send_asset(conn, recipient_addr, "gold", 100) # # # 2. Send the NFT 'painting_001' # # NFTs require a nested list structure specifying the parent and the token name # nft_transfer <- list( # art = list( # token = "painting_001", # qty = 1 # ) # ) # mc_send(conn, recipient_addr, nft_transfer) # # # 3. Inspect the recipient's token balances # # The output is a clean data frame with an 'address' column # recipient_tokens <- mc_get_token_balances(conn, recipient_addr) # print(recipient_tokens) ## ----cleanup------------------------------------------------------------------ # mc_node_stop(conn) # Sys.sleep(2) # # # Determine data directory for cleanup # if (.Platform$OS.type == "windows") { # base_dir <- file.path(Sys.getenv("APPDATA"), "MultiChain") # } else if (Sys.info()["sysname"] == "Darwin") { # base_dir <- file.path(Sys.getenv("HOME"), "Library/Application Support/MultiChain") # } else { # base_dir <- file.path(Sys.getenv("HOME"), ".multichain") # } # # chain_dir <- file.path(base_dir, chain_name) # if (dir.exists(chain_dir)) unlink(chain_dir, recursive = TRUE)