colstrom / niftygate

Drop-in Access Control via NFT Ownership
MIT License
71 stars 14 forks source link

How to: Compile niftygate as a library, and embed it in your application. #2

Open packetlost opened 1 year ago

packetlost commented 1 year ago

I have a non-web application, and I want to interface with Smart Contracts Compile niftygate as a library, and embed it in your application.

Having issues running the demo; how do you create a library from Niftygate?

colstrom commented 1 year ago

Heya, thanks for taking the time to ask about this. There's a few different ways that things can be embedded, depending on what you're trying to do.

If you take a look at main.rs, it's just a very thin wrapper that invokes public functions that are exposed in the library (this is so that all the commands can be embedded in other crates, which is how the sub-crates like niftygate-guide and niftygate-contracts and such are embedded in the main crate, which you can see in action in command.rs).

If your project is in Rust, you can add either the main niftygate crate or any of its sub-crates as a dependency. A minimal example of what that might look like can be found in examples/proxy.rs (there are other examples in that directory as well).

If your project is not in Rust, I think you should be able to use the .so artifacts produced by cargo build --lib and link them in whatever manner is appropriate for the language you're working with. A tool like cbindgen may be helpful for generating FFI bindings if your context requires it.

I haven't had a context to test this particular scenario, so there may be some rough edges (and by "may", I mean it's quite likely). If you do end up going do that path, and encounter issues with the library (such as interfaces that aren't exposed and need to be or something like that), please let me know and I'll see what I can do to improve things.

Hopefully that answers your questions!

May I ask what issues you encountered running the demo? Maybe there's something I can help with (or fix) there.