EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

how do we get the Serialize.SerialBuffer in browser #548

Closed dominic-healid closed 3 years ago

dominic-healid commented 5 years ago

I'm having issues with setabi, please help how to achieve this on browser. I am able to setcode but not with setabi.

tbfleming commented 5 years ago

Try something like this:

const buffer = new SerialBuffer({
  textEncoder: api.textEncoder,
  textDecoder: api.textDecoder,
});
api.abiTypes.get('abi_def').serialize(buffer, JSON.parse(abi));
const converted = buffer.asUint8Array();
dominic-healid commented 5 years ago

@tbfleming I need to reference the SerialBuffer, something like an import function. That's what I need to know because I can't use SerailBuffer without referencing, I'm getting undefined error.

tbfleming commented 5 years ago

It's in the Serialize module, which is exported from the top level.

tbfleming commented 5 years ago

Added to docs label: these probably need to go in the docs. Please keep open until then.

  1. How to setabi
  2. How to access the eosjs submodules
dominic-healid commented 5 years ago

@tbfleming can you please give me some pointers how to access the SerialBuffer? I'm still getting SerialBuffer is not defined

Really need some help with been struggling with this for a few days now.

tbfleming commented 5 years ago

What toolchain are you using to build your browser app? webpack? browserify? other? none? each method has a different approach to accessing the modules which make up eosjs.

dominic-healid commented 5 years ago

webpack, on the dist-web folder I only got, eosjs-api, eosjs-jssig, eosjs-jsonrpc

tbfleming commented 5 years ago

The dist-web folder isn't designed to work with webpack and restricts the set of available modules.

If you're using webpack with Babel, import modules using the instructions at https://eosio.github.io/eosjs/latest/basic-usage/es-modules

If you're using webpack without Babel, import modules using the instructions at https://eosio.github.io/eosjs/latest/basic-usage/commonjs

Either method allows you to import Serialize, which contains SerialBuffer

sanaraufx commented 3 years ago

Cleaning up old issues so we can focus on more recent issues. Please reopen this ticket if needed. Thank you.