If you are looking for the the previous version of eosjs you can find it here.
Javascript API for integration with EOSIO-based blockchains using EOSIO RPC API.
Documentation can be found here
npm install eosjs@beta
consteosjs=require('eosjs');constfetch=require('node-fetch');// node only; not needed in browsersconst{ TextDecoder, TextEncoder }=require('text-encoding');// node, IE11 and IE Edge BrowsersSignatureProvider holds private keys and is responsible for signing transactions
constdefaultPrivateKey="5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr";// useraaaaaaaaconstsignatureProvider=neweosjs.SignatureProvider([defaultPrivateKey]);Open a connection to JSON-RPC, include fetch when on NodeJS
constrpc=neweosjs.Rpc.JsonRpc('http://127.0.0.1:8000',{ fetch });Include textDecoder and textEncoder when using in browser.
constapi=neweosjs.Api({ rpc, signatureProvider,textDecoder: newTextDecoder(),textEncoder: newTextEncoder()});(async()=>{constresult=awaitapi.transact({actions: [{account: 'eosio.token',name: 'transfer',authorization: [{actor: 'useraaaaaaaa',permission: 'active',}],data: {from: 'useraaaaaaaa',to: 'useraaaaaaab',quantity: '0.0001 SYS',memo: '',},}]},{blocksBehind: 3,expireSeconds: 30,});console.dir(result);})();use eosjs_jsonrpc.RpcError for handling JSON-RPC Errors
...
try{constresult=awaitapi.transact({
...
}catch(e){console.log('\nCaught exception: '+e);if(einstanceofeosjs_jsonrpc.RpcError)console.log(JSON.stringify(e.json,null,2);}...After running npm run build-web or yarn build-web, the browser distribution will be located in dist. For full browser usage examples, see the documentation.
transact() is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of broadcast: true, and can be used to fill TAPOS fields given blocksBehind and expireSeconds. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (expiration, ref_block_num, ref_block_prefix) and will automatically be broadcast onto the chain.
npm run test or yarn test
npm run build-weboryarn build-web- Open
test.htmlin your browser of choice
The integration tests assume that you have a local node for EOS set up at localhost:8000. The test.html file should run through 5 test cases with the final showing an exception on the screen for missing required TAPOS.