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:


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.