Coder Social home page Coder Social logo

eosjs-api's Introduction

NPM

Eos API

Application programming interface to EOS blockchain nodes. This is for read-only API calls. If you need to sign transactions use eosjs instead.

Include

  • Install with: npm install eosjs-api
  • Html script tag, see releases for the correct version and its matching script integrity hash.
<html>
<head>
  <meta charset="utf-8">
  <!--
  sha512-n3CgU6w9TJVf/pVIMHYhk3Gxv8lEQYjVrSSTLXvEBENLF+CQd1Kp0jxXj09yGUOkWerdv2mJlh1Mnz3aRfYqWw== lib/eos-api.js
  sha512-Cj2FQb94MMtDPgHb1R1577pEMjYhc+P5pNgv1/QwoJD9ntuR9rnWlqJACS/xNniNK5cFS6Y6CpQlHWpzWUeEbw== lib/eos-api.min.js
  sha512-4C6oDKarS8DaXO99o342USbeQwqW98qik+QSzVGfof939gUpIyRDCnbGIGQAIkLNpYZIV4XanmRy3wcis6UW8w== lib/eos-api.min.js.map
  -->
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/eos-api.min.js"
    integrity="sha512-LLDsX/GdVZYA82k9TVz3zUxSjvaX8s5b1FJm64W51JGxLFKI2z+ljqYQtsUZIOxh9pSUqvLA5HCoxXqdRxusKw=="
    crossorigin="anonymous"></script>

</head>
<body>
  See console object: EosApi
</body>
</html>

EosApi

Run nodeos

Usage

EosApi = require('eosjs-api') // Or EosApi = require('./src')

eos = EosApi() // // 127.0.0.1:8888

// Any API call without a callback parameter will print documentation: description,
// parameters, return value, and possible errors.  All methods and documentation
// are created from JSON files in eosjs/json/api/v1..
eos.getInfo()

// A Promise is returned if a callback is not provided.
eos.getInfo({}).then(result => console.log(result))
eos.getBlock(1).then(result => console.log(result))

// For callbacks instead of Promises provide a callback
callback = (err, res) => {err ? console.error(err) : console.log(res)}

// The server does not expect any parameters only the callback is needed
eos.getInfo(callback)

// Parameters are added before the callback
eos.getBlock(1, callback)

// Parameters can be an object
eos.getBlock({block_num_or_id: 1}, callback)
eos.getBlock({block_num_or_id: 1}).then(result => console.log(result))

Configuration

EosApi = require('eosjs-api') // Or EosApi = require('./src')

// everything is optional
options = {
  httpEndpoint: 'http://127.0.0.1:8888', // default, null for cold-storage
  verbose: false, // API logging
  logger: { // Default logging functions
    log: config.verbose ? console.log : null,
    error: config.verbose ? console.error : null
  },
  fetchConfiguration: {}
}

eos = EosApi(options)

options.logger example

During testing, an error may be expected and checked as follows:

options.logger = {
  error: err => {
    assert.equal(err, 'expected error')
    done()
  }
}

options.fetchConfiguration example

options.fetchConfiguration = {
  credentials: 'same-origin'
}

Every eosjs-api request will run fetch with this configuration:

fetch('https://example.com', {
  credentials: 'same-origin'
})

Environment

Node and browser (es2015)

eosjs-api's People

Contributors

jcalfee avatar jeffreyssmith2nd avatar tbfleming avatar umu618 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eosjs-api's Issues

What is the transaction_id_type

I don't think the docs is clear about what the transaction_id_type is, how it looks like. Please can someone explain or tell me what it is?

return null actions while using getActions.

I configured the file right and all other end points are working fine. But eos.getActions("account_name",-1,1).then((result)=> console.log(result)); is returning { actions: [], last_irreversible_block: 23070550 } But if I use cleos command it working fine : like this
cleos --url https://junglehistory.cryptolions.io:443 get actions account_name -1 -1 -j . I don't know what I am doing wrong here?

api object ?

Hi @jcalfee

I'm working on the camel wrapper for eosjs-api (ref EOSIO/eosjs#277) and noticed the following:


const EOSAPI = require('eosjs-api')
const eosApi = new EOSAPI()

Object.keys(eosApi).forEach(key => {
  console.log(`--> ${key} is ${typeof eosApi[key]}`)
})

console.log(eosApi.api)

output

--> getInfo is function
--> getAccount is function
--> getCode is function
--> getAbi is function
--> getRawCodeAndAbi is function
--> abiJsonToBin is function
--> abiBinToJson is function
--> getRequiredKeys is function
--> getBlock is function
--> getBlockHeaderState is function
--> getTableRows is function
--> getCurrencyBalance is function
--> getCurrencyStats is function
--> getProducers is function
--> getProducerSchedule is function
--> getScheduledTransactions is function
--> pushBlock is function
--> pushTransaction is function
--> pushTransactions is function
--> getActions is function
--> getTransaction is function
--> getKeyAccounts is function
--> getControlledAccounts is function
--> createTransaction is function
--> api is object
{ createTransaction: [Function: createTransaction] }

Why is there an api object with a createTransaction function ?

Is that a bug or does it have different utility ?

Could you add get_producers to chain.json ?

"get_producers": {
"brief": "Fetch smart contract data from producer.",
"params": {
"json": { "type": "bool", "default": false},
"lower_bound": {"type": "string", "default": "0"},
"limit": {"type": "uint32", "default": "10"}
},
"results": {
"rows": {
"type": "vector",
"doc": "one row per item, either encoded as hex String or JSON object"
},
"total_producer_vote_weight":{
"type": "float64",
"doc": "total vote"
},
"more": {
"type": "bool",
"doc": "true if last element"
}
}
},

get_actions returning unexpected result

Hello developers,
I am trying to use get_actions, but I am not able to apprehend the result.
I am passing
{"pos":0, "offset": 10, "account_name": "accountname"}
in my curl request on mainnet.
According to the docs, it should return me any array of [0,10), i.e. a total of 10 elements of [0,9].
But instead I am getting an array of 11 elements. Can't figure out the problem.

Thanks for any help! :)

It seems that abi information is not updated.

// eos/libraries/chain/eosio_contract_abi.cpp
eos_abi.structs.emplace_back( struct_def {
"transaction_header", "", {
{"expiration", "time_point_sec"},
{"ref_block_num", "uint16"},
{"ref_block_prefix", "uint32"},
{"max_net_usage_words", "varuint32"},
{"max_cpu_usage_ms", "uint8"},
{"delay_sec", "varuint32"}
}
});

max_kcpu_usage: 0,

How can I call a function that I have defined in the contract from my js ?

My target is to make an app that can be html or native. For now let it be web app. I have deployed a hello world contract in my local blockchain network. I have defined a function named "hi". I need to call this function from my web app through js and I'm using eosjs in browserify. Can anyone guide me through this ? It would be great if anyone can give me a solution here.

max_kcpu_usage(eosjs-api) => max_cpu_usage_ms (eos)

The headers' key name appears to be different from the recent code in eos

// libraries/chain/eosio_contract_abi.cpp (EOS)
eos_abi.structs.emplace_back( struct_def {
"transaction_header", "", {
{"expiration", "time_point_sec"},
{"ref_block_num", "uint16"},
{"ref_block_prefix", "uint32"},
{"max_net_usage_words", "varuint32"},
{"max_cpu_usage_ms", "uint8"},
{"delay_sec", "varuint32"}
}
});

// src/exported-helpers.js (eosjs-api)
api.getBlock(info.head_block_num - 3, checkError(callback, block => {
const expiration = new Date(chainDate.getTime() + expireInSeconds * 1000)
const headers = {
expiration: expiration.toISOString().split('.')[0],
region: 0,
ref_block_num,
ref_block_prefix: block.ref_block_prefix,
max_net_usage_words: 0,
max_kcpu_usage: 0,
delay_sec: 0,
context_free_actions: [],
actions: [],
signatures: [],

total_producer_vote_weight is not useful enough

Sorry to ask a question here:
with the get_producers API in chain.json, I only can get the total_producer_vote_weight.
but this value is not the SYS quantity, how can I figure out the percent of the current vote progress.

if I can get the total_producer_vote_quantity, I can simply calculate it with total_producer_vote_quantity / total_supply.

/v1/history/get_key_accounts

get_key_accounts endpoint not working, Always shows 404 not found,
for testnet
account name : lalaworld131
public key : EOS6FxXbikY5ZUN9qEdeLbEYLKZzJwRYRr2PuC3rqfSu67LvhPARi
not able to map public key to account name using this API

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.