{"id":19849658,"url":"https://github.com/geeks-solutions/ex_stacks_example","last_synced_at":"2025-02-28T20:44:26.258Z","repository":{"id":105004461,"uuid":"560433075","full_name":"Geeks-Solutions/ex_stacks_example","owner":"Geeks-Solutions","description":"This is an example application that showcases the implementation of ExStacks","archived":false,"fork":false,"pushed_at":"2022-12-05T20:32:26.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T13:10:33.001Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Geeks-Solutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-01T13:48:16.000Z","updated_at":"2022-12-24T14:23:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0906d14-e181-471d-9c66-cb2a36f510d9","html_url":"https://github.com/Geeks-Solutions/ex_stacks_example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geeks-Solutions%2Fex_stacks_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geeks-Solutions%2Fex_stacks_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geeks-Solutions%2Fex_stacks_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geeks-Solutions%2Fex_stacks_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geeks-Solutions","download_url":"https://codeload.github.com/Geeks-Solutions/ex_stacks_example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241230020,"owners_count":19930896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T13:22:25.875Z","updated_at":"2025-02-28T20:44:26.224Z","avatar_url":"https://github.com/Geeks-Solutions.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ExStacksExample\n\n# Introduction\n\nExStacksExample is an example app that showcases using the [Ex Stacks](https://github.com/Geeks-Solutions/ex_stacks) library\n\n# Setting up ExStacks\n\nIn the `config.exs` file, I've added the following node endpoint config:\n```elixir\nconfig :ex_stacks,\n  node_url: \"https://stacks-node-api.mainnet.stacks.co\",\n  node_ws_url: \"wss://stacks-node-api.testnet.stacks.co/extended/v1/ws\"\n```\n``node_ws_url`` is optional and will only be checked if you try to subscribe to / unsubscribe from a Stacks Blockchain websocket event.\n\n\n# Usage\nThere are 3 ways in how you can take advantage of the Ex Stacks library: \n\n### API Calls\n- These are one time synchronous requests, you can find all the available examples in `ExStacksExample.Examples`, all of these call the ``ExStacks.StacksAPI.request/2`` function. \n  - An example using the function:\n  ```elixir\n      StacksAPI.request(\"account_balances\", %{\n      principal: \"SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0\"\n    })\n  ```\n    - The first parameter in the request function is the named request that you would like to call, you can find the full list of available names in the ExStacks library.\n    - The second is the parameters map that will be used in the request, some of these are required and will return an error if not present, others are optional.\n\n##### Signing a transaxtion\n- To sign a transaction, you'll need to include the signature of the wallet signing the transaction, and the raw transaction, as well as specifying the network identifier.\nExample: \n```elixir\n StacksAPI.request(\n      \"sign_transaction\",\n      %{\n        network_identifier: %{\n          blockchain: \"stacks\",\n          network: \"mainnet\"\n        },\n        unsigned_transaction:\n          \"00000000010400539886f96611ba3ba6cef9618f8c78118b37c5be0000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003020000000000051ab71a091b4b8b7661a661c620966ab6573bc2dcd3000000000007a12074657374207472616e73616374696f6e000000000000000000000000000000000000\",\n        signatures: [\n          %{\n            signing_payload: %{\n              address: \"string\",\n              account_identifier: %{\n                address: \"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6\",\n                metadata: %{}\n              },\n              hex_bytes: \"string\",\n              signature_type: \"ecdsa\"\n            },\n            public_key: %{\n              hex_bytes: \"025c13b2fc2261956d8a4ad07d481b1a3b2cbf93a24f992249a61c3a1c4de79c51\",\n              curve_type: \"secp256k1\"\n            },\n            signature_type: \"ecdsa\",\n            hex_bytes: \"string\"\n          }\n        ]\n      }\n    )\n```\n\n##### Submitting a signed transaction\n- To submit a signed transaction, all you need to do is include the signed transaction (you can retrieve it by using the previous signing a transaction function) and the network identifier\nExample:\n```elixir\n StacksAPI.request(\"submit_signed_transaction\", %{\n      network_identifier: %{\n        blockchain: \"stacks\",\n        network: \"mainnet\"\n      },\n      signed_transaction:\n        \"0x80800000000400539886f96611ba3ba6cef9618f8c78118b37c5be000000000000000000000000000000b400017a33a91515ef48608a99c6adecd2eb258e11534a1acf66348f5678c8e2c8f83d243555ed67a0019d3500df98563ca31321c1a675b43ef79f146e322fe08df75103020000000000051a1ae3f911d8f1d46d7416bfbe4b593fd41eac19cb000000000007a12000000000000000000000000000000000000000000000000000000000000000000000\"\n    })\n```\n\n### Subscribing to events\n- These are websocket events that you can watch and wait for messages coming through the websocket.\n- ``node_ws_url`` is required to make use of this feature.\n- The websocket client implemented within the ExStacks library relays ALL subscribed event messages to ALL your subscribed processes, you'll need to handle which message to process. The format of the message will be ``{:event_atom, message}``\n- To add a new process that will receive messages, pass the optional ``:pid`` parameter to the subscribe function.\n- An example that implements this (also found in ``ExStacksExample.Examples``):\n```elixir\n  StacksAPI.subscribe(\"block\", %{pid: self()})\n\n    receive do\n      {:block, event} -\u003e\n        IO.inspect(event)\n    end\n\n    # In case you would like to stop receiving any event at all, add the pid to the unsubscribe params map\n    # Else don't add it, it will only stop listening to block updates\n    # But keep sending you other events if you subscribed prior\n    # StacksAPI.unsubscribe(\"block\")\n    StacksAPI.unsubscribe(\"block\", %{pid: self()})\n  ```\n### Unsubscribing from events\n- Similar requirements to subscribing to events.\n- Unsubscribe from websocket messages.\n- To also remove a process while unsubscribing to events, pass the ``:pid`` optional parameter to the unsubscribe function.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeks-solutions%2Fex_stacks_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeeks-solutions%2Fex_stacks_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeks-solutions%2Fex_stacks_example/lists"}