Eos = require('eosjs')

// Default configuration (additional options below)
config = {
  chainId: null, // 32 byte (64 char) hex string
  keyProvider: ['PrivateKeys...'], // WIF string or array of keys..
  httpEndpoint: 'http://127.0.0.1:8888',
  expireInSeconds: 60,
  broadcast: true,
  verbose: false, // API activity
  sign: true
}

eos = Eos(config)
  • chainId hex - 您要连接的区块链的唯一ID。这是有效交易签名所必需的。chainId通过 get_info API调用提供。通过其初始起源块识别链。签署的所有交易仅对具有此chainId的区块链有效。出于安全原因验证chainId。
  • keyProvider [array<string>|string|function] - 提供用于签署事务的私钥。如果找到多个私钥,get_required_keys则调用API 以发现要使用的签名密钥。如果提供了函数,则为每个事务调用此函数。
  • httpEndpoint string - 提供链API的nodeosd服务器的http或https位置。从浏览器使用eosjs时,请记住在nodeosd或代理服务器中配置相同的源策略。对于测试,access-control-allow-origin = *可以使用nodeosd配置。对于冷存储(无网络)配置,请将此值设置为null。
  • expireInSeconds number - 事务到期前的秒数。时间基于nodeosd的时钟。可能出现错误的未到期交易是到期日到期之前的责任,此时间应该是短暂的。
  • broadcast [boolean=true]- 将交易发布到区块链。使用false获取完全签名的事务。
  • verbose [boolean=false] - 详细日志记录,例如API活动。
  • debug [boolean=false] - 低级调试日志记录(序列化)。
  • sign [boolean=true] - 使用私钥签署交易。保留未签名的交易避免了提供私钥的需要。
  • mockTransactions(高级)
    • mockTransactions: () => null // 'pass', or 'fail'
    • pass - 不要广播,总是假装交易有效
    • fail - 不要广播,假装交易失败
    • null|undefined - 照常广播
  • transactionHeaders(高级) - 手动计算事务头。这可能是提供的,因此eosjs不需要对nodeos进行与头相关的API调用。用于冷藏等环境。每个事务都会调用此回调。这里记录了标题eosjs-api#headers
    • transactionHeaders: (expireInSeconds, callback) => {callback(null/*error*/, headers)}
  • logger 默认日志记录配置。
    logger: {
    log: config.verbose ? console.log : null,
    error: console.error // null to disable
    }

    关闭所有错误记录: config.logger = {error: null}