EOSCommunity.org Forums

An eosjs based example for the initial Resource Provider specification

As a follow up to the initial Resource Provider specification, I spent a bit of time creating a Javascript example using eosjs to access it and perform a transaction.

You can read more about the general implementation in the original thread here:

https://forums.eoscommunity.org/t/initial-specification-for-the-resource-provider-api-endpoint/1546/3

The example code I’m sharing today is fully functional and works on the EOS mainnet. It is designed to run in nodejs as an example but should be able to be adapted for browser based applications as well.

You can find the code here:

In order to run this code, you’ll need the following packages installed:

  • node-fetch
  • eosjs
  • eosjs-ecc

The only required changes you’ll need to make before running the code is to set the signer and privateKey values.

Other aspects can also be changed to your liking, including:

  • The example actions/transaction can also be modified to be any transaction.
  • The maxFee can be set to any numeric value to cap the amount to spend per-transaction. Set it to 0 if you only want free transactions.
  • The httpEndpoint, resourceProviderEndpoint, and chainId can all be changed to make it work on another chain. Jungle 3, Telos, and WAX will all work. An example for Jungle 3 would be:
const httpEndpoint = "https://jungle3.greymass.com"
const resourceProviderEndpoint = "https://jungle3.greymass.com/v1/resource_provider/request_transaction"
const chainId = "2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840"

This code could be further changed to work with UAL, Transit, ScatterJS, or any other eosjs-based framework that handles transactions.

As the Resource Provider specification continues to evolve, we will likely be releasing a library to handle all of these types of integrations directly. It however will not use eosjs, which is why we are publishing this example for any applications that use eosjs and want to implement something like this now.

2 Likes

Any update on this library? What’s the latest guidance for applications that want to handle user resources using your @greymass/eosio library?

No meaningful development on it yet, but a lot of thought going into it. The idea for this library has evolved from something completely standalone to being a part of comprehensive suite to replace UAL… which is a pretty big project.

We do have some example code using @greymas/eosio though - I could get a post out similar to this one using it if you’re interested.

That would be great! Many projects are moving away from eosjs.

1 Like

Hi, if folks are moving away from eosjs what are they moving too?

I found eosjs out of date with conflicting dependancies. I found and fixed and submitted a pull request with updates. NOTE: in my pull request I renamed the package mandle-eosjs and reset version to 1.0.0. Thoughts on the name/version change?