Morpheos
This library allows you to use any version of eosjs
indistinctly.
It also contains some useful features for combining actions and transactions together and using different authorization formats.
Installation
npm install morpheos
You will also need eosjs
:
npm install eosjs# or npm install eosjs@16.0.9
Usage
First, construct your eosjs
instance.
Version <= 16.0.9
const eos = ;
Version >= 20.0.0
const signatureProvider = 'some-private-key';const rpc = 'https://api.jungle.alohaeos.com' fetch ; const eos = rpc signatureProvider textEncoder: textDecoder: ;
Then, pass it to the Morpheos constructor:
const morph = eos; { await morph; await morph; await morph;}
Transaction class
Morpheos also provides a Transaction
class to easily combine actions
and transactions together.
const t1 = someAction;const t2 = action1 action2;const t3 = t1 t2 action3; console;// [someAction, action1, action2, action3] await morph
Pass a Morpheos
instance to the Transaction
constructor to make your
transactions easily sendable.
{ return account: 'eosio' name: 'buyram' authorization: actor: account permission: 'active' data: payer: account receiver: account quant: amount morph;} const transaction = ;await transaction;// or justawait ; // Can also provide transact optionsawait transaction;
Combine transactions easily:
{ return account: 'eosio.token' name: 'transfer' authorization: actor: from permission: 'active' data: from to quantity: amount memo: 'Morpheos is cool' morph;} await ;
FlexAuth
When defining actions (for morph.transact(...)
or new Transaction(...)
), Morpheos
allows you to specify the authorization
field in multiple formats:
const action = account: 'eosio.token' name: 'transfer' authorization: actor: 'myaccount' permission: 'active' data: from: 'myaccount' 'youraccount' '1.0000 EOS' memo: 'Morpheos is awesome' ; actionauthorization = 'myaccount'; // Defaults to permission: 'active'actionauthorization = 'myaccount@owner'; // '<actor>@<permission>'actionauthorization = actor: 'myaccount' permission: 'active' ; // EOSIO formatactionauthorization = name: 'myaccount' authority: 'owner' ; // Scatter account formatactionauthorization = name: 'myaccount' ; // Scatter account format, defaults to permission: 'active'// Can specify multiple authorizations if necessaryactionauthorization = 'myaccount' 'youraccount@owner' name: 'otheraccount' ;
You can also extract the specified account name from any of these authorization formats by using:
const accountName = Transaction;
Which allows you to pass that flexibility to the consumers of your code very easily:
{ return account: 'eosio.token' name: 'transfer' authorization: from // Just provide the FlexAuth here data: from: Transaction // And extract the account name here to quantity: amount memo: 'Morpheos is wonderful' morph;} // Then, any of these will work:await ;await ;await ;await ;
Asset
Morpheos also provides an Asset
class to manipulate EOSIO assets more easily:
let a = '42.0000 EOS'; // From string representationa = 42 'EOS' 4; // From amount, symbol, precisiona; // '42.0000 EOS' // Arithmetic operationslet b = a; // Does not change `a`, just returns resultb = a; // Can also pass the string representation directlyb = a; // Also supports negative amountsb = a;b = a; // Comparison operatorsa;a; // Can also pass the string representation directlya;a;a;a;a;a;a;a;
Contributing
Please submit an issue if you find any bugs or if you would like to suggest a feature.