###### Dev: Mariano Agüero # Take Home Interview Project, my personal journey. ### Introduction First of all, I read the tech challenge and tried to organize myself to make it happen. I prioritized what I had to do to make it in a decentralized world. We can say that I made a separation in "layers", of what I needed to do: - Blockchain (Node and Farmer): First of all I would have to have a blockchain, either running locally, or a testnet running and being maintained by the Subspace team (something similar to Rinkeby, Kovan on Ethereum, or Fuji for Avalanache, that's the idea). - Wallet: install and use a Wallet that injects a provider to communicate with the blockchain, in this case Subspace Wallet or Polkadot Js extension for Google Chrome. - An application, that uses the subspace.js library together with the injected Provider, to do "something". #### First idea: a KYC, using the subspace.js library. #### Second idea: CLI Tool, using the subspace.js library. In order to realize the first idea, I had to validate that all the layers work, in case something doesn't work as I expect, I will go for the second idea. Let's go! ### Step 1 - Blockchain I tried to build a Docker, locally, following these instructions (https://github.com/subspace/subspace/blob/main/docs/farming.md). Unfortunately I encountered some node sync errors, and it seemed that it never finished synchronizing. After discarding that option, I went on to try to use the binaries directly on my Mac, using these instructions (https://github.com/subspace/subspace/blob/main/docs/development.md). I downloaded the releases from here (https://github.com/subspace/subspace/releases). I gave them permissions and ran them with their respective arguments. It worked fine! I tried to connect it to the Polkadot explorer, and well, I succeeded. I started to play a little with the explorer, I noticed that I could not send coin transfers between accounts, that seemed strange to me. I started to investigate a little more, I went to discord. In discord I found comments from other users that said that the transfer was disabled for the moment, which on the one hand left me calm, but on the other hand, I felt that the possibility of doing "things" as a transfer between users, could not be done. ### Step 2 - Wallet First install the Polkadot{.js} extension, play with it for a while. I also tried to make transfers there without success. I realized at one point, that I could not add my local node/farmer to the wallet to use as a chain (there is no "add chain" button or something like that). There was no option to add a new one to the wallet, to do it manually, and no link or option in the polkadot explorer to add it (as suggested in the forum discussion, in the metadata section of the Polkadot explorer). I found it very strange, and it left me worried. If I can't add the correct chain, with its respective RPC, I will have no way for the wallet to correctly inject the provider to interact with my local chain. ### Step 3 - Application I already had a problem, I couldn't add a chain to my Wallet, so I thought how do I find out if this is the only problem I have, or is there something else here that makes me give up on the first idea as a solution. I downloaded an example that is in the subspace.js library(a dApp) and tried to make it work locally. It worked, but only in testnet(I could not get it to work with a local node because I have no way to add the chain in the wallet,), and the option to get back the object ID related to the image that was stored, did not work well (we have to wait several blocks to get the objectId, and the example did not contemplate it). Possibly, we would have to create some waiting pattern until the object is available. Also, sometimes, with an address created by me from the wallet, I was getting an error that the address was not valid (so another problem here). ### Decision All this made me go for the idea of creating a CLI tool using the subspace library, something simpler, more creative and possibly more useful to the community, to do with the time I had left after researching nodes, farmer, explorer and wallets, and dealing with the typical problems of onboarding to a new technology. ### How I build it - I used the oclif library (https://github.com/oclif/oclif) - I used subspace.js library(https://github.com/subspace/subspace.js ) - I used a local node/farmer, running latest releases - I published the cli tool in npm , https://www.npmjs.com/package/subspace-cli ### Step by step - First of all, I created the structure with oclif in typescript. - Then I added the subspace.js library, and started to create an abstract class to handle the chain and the mnemonic, since it will be something that will be used in most of the commands and it will be repeated code. - Once the abstract class was created, I proceeded to create the two commands for the storage, one that create and submit a signed put transaction and return an objectId. Another one that gets the file associated to the objectId as Uint8Array. - I tested both methods, locally, worked fine!! That's great news. - Created some tests, for each method. - I updated the readme, with the commands. - I published the tool in npm. ### how to run it in the development environment - clone the repository https://github.com/mariano-aguero/subspace-cli and install it. - download the latest releases to run a node and a farmer for subspace labs. - in different terminal tabs, run the node and the farmer on local ``` $ ./subspace-node-macos-x86_64-gemini-2a-2022-oct-06 --dev --tmp $ ./subspace-farmer-macos-x86_64-gemini-2a-2022-oct-06 farm --reward-address 5HYweGmCf9dc7mi67XcnpzyF9TuYuaZydQf8viBSfpZLpkma --plot-size 10G ``` - in another terminal tab, go to the folder where we cloned the project and install it, we can execute the commands using as a base this `./bin/dev`. - execute the put command with some file, to create and submit a signed put transaction and return an objectId, here an example ``` $ ./bin/dev storage:put --file ./example.jpeg ``` - execute the get command with the object Id, to obtain the file, here an example ``` $ ./bin/dev storage:get --objectId bfdcac2c580955e05913add271639e72ffdb6507b42dfcd16960717727918df8 ``` ### Useful links - Project repository: https://github.com/mariano-aguero/subspace-cli - Cli tool published: https://www.npmjs.com/package/subspace-cli ### Some images of the project: Node ![](https://i.imgur.com/Me4xwyy.jpg) Farmer ![](https://i.imgur.com/gk9VJYj.jpg) Explorer ![](https://i.imgur.com/HGlMCzd.png) Cli tool in action ![](https://i.imgur.com/QdiLZsa.png) ### Conclusion Well, on our journey to realizing the cli tool we encountered many details. I think they are mostly small problems typical of an ecosystem in constant development, where we could create a troubleshooting guide, and possibly some improvements to many readmes that are still around. I think a cli tool can help in the process of the development of applications, and to test/confirm values/objects in the blockchain quickly, and can be welcome in the community. I was left with the desire to do a KYC, I think something I will do personally and share later.