Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
packetlost opened this issue Jul 10, 2023 · 1 comment
Assignees

Comments

@packetlost
Copy link

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
Copy link
Owner

colstrom commented Aug 2, 2023

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.

@colstrom colstrom self-assigned this Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants