f8n-pvinis-lib
v0.2.0
Published
Get foundationed.
Downloads
14
Readme
a bunch of trials here: 0xD72a90e87c79452d1f03f4ABAb09d31C3F80536F
- make lib
- add tests
- use git tags for lib in package.json deps
- add lib to example and readme instructions
- make some way (.env?) to change the address of the f8n contract
i would probably not use that template to generate this repo https://github.com/tomchen/example-typescript-package
not sure what to do for cjs, modules, es6, etc for exports from ts
maybe ethers could be a peer dep
i didnt like i have to setup the whole project
Setup
Install,
npm add x
,yarn add x
import { bla } from "x"
use to deploy
use to mint
Contributing
- docs about npm link
Log
I created a vite app which will end up being the app that will import the final lib.
I made it so that the app fully works, and then extracted the code that will become the lib. That way I could have a clear "api" for my lib. What is called, where, and how.
I had to download the ABIs for both the factory and the collection contracts, and generate types for these to use with typescript.
For a future version of this lib, I would have some scripts to pull the latest ABIs and generate the types. For this version, pulling is manual, and after the ABIs are in the
./abi
directory, I can runnpm run generate-types
to get freshly generated types in./src/types
.eg: https://api.etherscan.io/api?module=contract&action=getabi&address=0xe38f942db7a1b4213d6213f70c499b59287b01f1&apiKey=your-api-key-here
I assume metamask is installed on the browser, to make it easier for me to develop this.
In a very near future version of the lib, I would add support for walletconnect etc, with the usual popup and all that jazz. That's key to lib adoption.
For the lib, I decided to go for a simple function that takes a
provider
and returns thecreateCollection
andmint
functions, all set up with the provider.I could have put the
signer
at the start function, but I decided not too. I think keeping it as an argument to the functions is a bit more verbose and explicit, but it is an important part of the functions, and having it as an arg reminds that to the user of the lib.I could have used a class or some other "singleton" situation to keep the provider and signer for all things, but again, I went for the simple solution.
The
mint
function is returning the token id at the end of a successful transaction.I wanted to "hide" the transaction id since the request for this lib is to hide as much of the web3 things from the user of the lib, and make it more like any other regular lib.
I know the choice of keeping the signer as an arg goes against the above, but I still think this is one important bit that is worth having repeated. Very easy to change and hide it though, if we decide the api must hide as many web3 things as possible.
For types, I hooked on things like
Parameters<FNDCollectionABI["mint"]>[0]
in order to have a direct type connection for the things i just pass on, and a separate type when I use them elsewhere likestring
orSigner
.This helps me for when the contract changes, and the ABI is updates, so the types might be different. If that happens, then typescript will complain for possible breakages.
That is not enough, because maybe two args of the same type might swap places, so typescript will have no type issues, but things like the
CollectionCreated
filter might break. For these cases I would write tests. I will not write tests here, but I would not ship this to npm without tests. I have used things like hardhat and set up tests, but I have not set up tests on a lib that calls to contracts, and I think that might take a bit too much time for me to try and set up, and it's not required for this assignment. My guess is that with hardhat the contract would run on a local node, and then the tests can run and verify a few things like the newly created collection extraction.I left some commented out
console.log
s in there, just for easy debugging for this assignment.Since I only have the addresses to mainnet and goerli for the f8n factory, I throw when someone tries to use any other network.
In the future this would be best to allow for .env value setting.
Future plans
- support for walletconnect.
- tests for the actual functions.
- scripts for ABIs pulling.
- event listener for events like txn started, pending, succeeded, failed?
- support for web3js and not just ethersjs for
provider
. - support for .env file, for FND_COLLECTION_FACTORY_ADDR etc.