factom
Version:
Library to build applications on the Factom blockchain
1,446 lines (952 loc) • 99.2 kB
Markdown
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
* [FactomEventEmitter][1]
* [Parameters][2]
* [Examples][3]
* [\_isBlockchainEvent][4]
* [Parameters][5]
* [\_isValidBlockEvent][6]
* [Parameters][7]
* [\_isValidPendingTransactionEvent][8]
* [Parameters][9]
* [chainSubscriptions][10]
* [factoidAddressPendingTransactionSubscriptions][11]
* [factoidAddressSubscriptions][12]
* [getPendingTransactions][13]
* [Parameters][14]
* [isPolling][15]
* [getSubscriptionToken][16]
* [Parameters][17]
* [FactomCli][18]
* [Parameters][19]
* [Examples][20]
* [add][21]
* [Parameters][22]
* [addChain][23]
* [Parameters][24]
* [addChains][25]
* [Parameters][26]
* [addEntries][27]
* [Parameters][28]
* [addEntry][29]
* [Parameters][30]
* [chainExists][31]
* [Parameters][32]
* [commit][33]
* [Parameters][34]
* [commitChain][35]
* [Parameters][36]
* [commitEntry][37]
* [Parameters][38]
* [createEntryCreditPurchaseTransaction][39]
* [Parameters][40]
* [createFactoidTransaction][41]
* [Parameters][42]
* [factomdApi][43]
* [Parameters][44]
* [getAdminBlock][45]
* [Parameters][46]
* [getAllEntriesOfChain][47]
* [Parameters][48]
* [getBalance][49]
* [Parameters][50]
* [getChainHead][51]
* [Parameters][52]
* [getDirectoryBlock][53]
* [Parameters][54]
* [getDirectoryBlockHead][55]
* [getEntry][56]
* [Parameters][57]
* [getEntryBlock][58]
* [Parameters][59]
* [getEntryCreditBlock][60]
* [Parameters][61]
* [getEntryCreditRate][62]
* [getEntryWithBlockContext][63]
* [Parameters][64]
* [getFactoidBlock][65]
* [Parameters][66]
* [getFirstEntry][67]
* [Parameters][68]
* [getHeights][69]
* [getPrivateAddress][70]
* [Parameters][71]
* [getTransaction][72]
* [Parameters][73]
* [reveal][74]
* [Parameters][75]
* [revealChain][76]
* [Parameters][77]
* [revealEntry][78]
* [Parameters][79]
* [rewindChainWhile][80]
* [Parameters][81]
* [Examples][82]
* [sendTransaction][83]
* [Parameters][84]
* [waitOnCommitAck][85]
* [Parameters][86]
* [waitOnFactoidTransactionAck][87]
* [Parameters][88]
* [waitOnRevealAck][89]
* [Parameters][90]
* [walletdApi][91]
* [Parameters][92]
* [addressToKey][93]
* [Parameters][94]
* [addressToRcdHash][95]
* [Parameters][96]
* [AdminBlock][97]
* [Properties][98]
* [getEntriesOfTypes][99]
* [Parameters][100]
* [EntryBuilder][101]
* [Parameters][102]
* [blockContext][103]
* [Parameters][104]
* [build][105]
* [chainId][106]
* [Parameters][107]
* [content][108]
* [Parameters][109]
* [extId][110]
* [Parameters][111]
* [extIds][112]
* [Parameters][113]
* [timestamp][114]
* [Parameters][115]
* [TransactionBuilder][116]
* [Parameters][117]
* [build][118]
* [input][119]
* [Parameters][120]
* [output][121]
* [Parameters][122]
* [rcdSignature][123]
* [Parameters][124]
* [timestamp][125]
* [Parameters][126]
* [Entry][127]
* [Parameters][128]
* [Properties][129]
* [Examples][130]
* [chainIdHex][131]
* [contentHex][132]
* [ecCost][133]
* [extIdsHex][134]
* [hash][135]
* [hashHex][136]
* [marshalBinary][137]
* [marshalBinaryHex][138]
* [payloadSize][139]
* [rawDataSize][140]
* [remainingFreeBytes][141]
* [remainingMaxBytes][142]
* [size][143]
* [toObject][144]
* [builder][145]
* [Parameters][146]
* [Transaction][147]
* [Parameters][148]
* [Properties][149]
* [Examples][150]
* [computeEcRequiredFees][151]
* [Parameters][152]
* [computeRequiredFees][153]
* [Parameters][154]
* [isSigned][155]
* [marshalBinary][156]
* [validateFees][157]
* [Parameters][158]
* [builder][159]
* [Parameters][160]
* [FactomdCli][161]
* [Parameters][162]
* [call][163]
* [Parameters][164]
* [WalletdCli][165]
* [Parameters][166]
* [call][167]
* [Parameters][168]
* [Chain][169]
* [Parameters][170]
* [Properties][171]
* [ecCost][172]
* [idHex][173]
* [toObject][174]
* [composeChain][175]
* [Parameters][176]
* [composeChainCommit][177]
* [Parameters][178]
* [composeChainCommitDelegateSig][179]
* [Parameters][180]
* [composeChainDelegateSig][181]
* [Parameters][182]
* [composeChainReveal][183]
* [Parameters][184]
* [composeEntry][185]
* [Parameters][186]
* [composeEntryCommit][187]
* [Parameters][188]
* [composeEntryCommitDelegateSig][189]
* [Parameters][190]
* [composeEntryDelegateSig][191]
* [Parameters][192]
* [composeEntryReveal][193]
* [Parameters][194]
* [computeChainId][195]
* [Parameters][196]
* [computeChainTxId][197]
* [Parameters][198]
* [computeEntryTxId][199]
* [Parameters][200]
* [ConnectionOptions][201]
* [Properties][202]
* [Examples][203]
* [DirectoryBlock][204]
* [Properties][205]
* [EntryBlock][206]
* [Properties][207]
* [EntryBlockContext][208]
* [Properties][209]
* [EntryCreditBlock][210]
* [Properties][211]
* [getCommitsForMinute][212]
* [Parameters][213]
* [FactoidBlock][214]
* [Properties][215]
* [getCoinbaseTransaction][216]
* [generateRandomEcAddress][217]
* [generateRandomFctAddress][218]
* [getPublicAddress][219]
* [Parameters][220]
* [isValidAddress][221]
* [Parameters][222]
* [isValidChainId][223]
* [Parameters][224]
* [isValidEcAddress][225]
* [Parameters][226]
* [isValidFctAddress][227]
* [Parameters][228]
* [isValidPrivateAddress][229]
* [Parameters][230]
* [isValidPrivateEcAddress][231]
* [Parameters][232]
* [isValidPrivateFctAddress][233]
* [Parameters][234]
* [isValidPublicAddress][235]
* [Parameters][236]
* [isValidPublicEcAddress][237]
* [Parameters][238]
* [isValidPublicFctAddress][239]
* [Parameters][240]
* [keyToPublicEcAddress][241]
* [Parameters][242]
* [keyToPublicFctAddress][243]
* [Parameters][244]
* [rcdHashToPublicFctAddress][245]
* [Parameters][246]
* [seedToPrivateEcAddress][247]
* [Parameters][248]
* [seedToPrivateFctAddress][249]
* [Parameters][250]
* [TransactionAddress][251]
* [Parameters][252]
* [TransactionBlockContext][253]
* [Properties][254]
## FactomEventEmitter
[src/factom-event-emitter.js:58-459][255]
**Extends EventEmitter**
Listen for new Factom Events:
<ul>
<li>newDirectoryBlock - Triggers when blockchain adds a new directory block. Listener receives new directory block.</li>
<li>newFactoidBlock - Triggers when blockchain adds a new factoid block. Listener receives new factoid block.</li>
<li>newAdminBlock - Triggers when blockchain adds a new admin block. Listener receives new admin block.</li>
<li>newEntryCreditBlock - Triggers when blockchain adds a new entry credit block. Listener receives new entry credit block.</li>
<li>newChain - Triggers when blockchain adds a new chain. Listener receives first entry block of new chain.</li>
<li>FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC - Triggers when factoid address sends or receives a transaction. Listener receives transaction.</li>
<li>4060c0192a421ca121ffff935889ef55a64574a6ef0e69b2b4f8a0ab919b2ca4 - Triggers when entry chain adds new entry block. Listener receives entry block.</li>
<li>newPendingTransaction:FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC - Triggers when factoid address receives a new pending transaction.</li>
</ul>
### Parameters
* `cli` **[FactomCli][256]** FactomCli instance to be used by the FactomEventEmitter instance to fetch blockchain data.
* `opts` **[object][257]?** Options to set on the FactomEventEmitter instance (optional, default `{}`)
* `opts.interval` **[number][258]** Interval (ms) at which the FactomEventEmtitter instance should poll the blockchain to check for a new block. (optional, default `7500`)
### Examples
```javascript
const { FactomCli, FactomEventEmitter } = require('factom');
const cli = new FactomCli();
// Poll the blockchain every 10s
const emitter = new FactomEventEmitter(cli, { interval: 10000 });
emitter.on('newDirectoryBlock', (directoryBlock) => ...);
emitter.on('newFactoidBlock', (factoidBlock) => ...);
emitter.on('newAdminBlock', (adminBlock) => ...);
emitter.on('newEntryCreditBlock', (entryCreditBlock) => ...);
emitter.on('newChain', (entryBlock) => ...);
// Listen to any transaction involving a given Factoid address
emitter.on('FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC', (transaction) => ...);
// Listen to any new entries in a given chain
emitter.on('4060c0192a421ca121ffff935889ef55a64574a6ef0e69b2b4f8a0ab919b2ca4', (entryBlock) => ...);
// Listen to any pending transactions involving a given Factoid address
emitter.on(FactomEventEmitter.getSubscriptionToken({
eventType: 'newPendingTransaction', topic: 'FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC'
}), (pendingTransaction) => ...);
```
### \_isBlockchainEvent
[src/factom-event-emitter.js:222-230][259]
Determine if a given event is a valid blockchain event
#### Parameters
* `event` **[string][260]**
Returns **[boolean][261]**
### \_isValidBlockEvent
[src/factom-event-emitter.js:199-201][262]
Determine if a given event is a valid block event
#### Parameters
* `event` **[event][263]**
Returns **[boolean][261]**
### \_isValidPendingTransactionEvent
[src/factom-event-emitter.js:208-215][264]
Determine if a given event is a valid pending transaction event
#### Parameters
* `event`
* `null-null` **[string][260]** event
Returns **[boolean][261]**
### chainSubscriptions
[src/factom-event-emitter.js:97-99][265]
Get active chain id subscriptions
Returns **[Set][266]<[string][260]>**
### factoidAddressPendingTransactionSubscriptions
[src/factom-event-emitter.js:113-115][267]
Get active factoid pending transactions subscriptions
Returns **[Map][268]<[string][260], [Set][266]<[string][260]>>**
### factoidAddressSubscriptions
[src/factom-event-emitter.js:105-107][269]
Get active factoid address subscriptions
Returns **[Set][266]<[string][260]>**
### getPendingTransactions
[src/factom-event-emitter.js:450-458][270]
Get pending FCT transactions for a given FCT address
#### Parameters
* `address`
* `null-null` **[string][260]** address
Returns **[array][271]** Array of pending FCT transactions
### isPolling
[src/factom-event-emitter.js:121-123][272]
Determine whether or not polling is currently active.
Returns **[boolean][261]**
### getSubscriptionToken
[src/factom-event-emitter.js:66-68][273]
Given an event configuration object returns a tokenized string
#### Parameters
* `event` **[Object][257]** The event configuration object
* `event.eventType` **[string][260]** The type of event e.g. newPendingTransaction
* `event.topic` **[string][260]** The topic e.g. A Factoid address
Returns **[string][260]**
## FactomCli
[src/factom-cli.js:28-586][274]
Main class to read and write data from Factom blockchain.
### Parameters
* `opts` **[Object][257]?** Options of connection to factomd and factom-walletd.
* `opts.factomd` **[ConnectionOptions][275]?** Options of connection to factomd.
* `opts.walletd` **[ConnectionOptions][275]?** Options of connection to factom-walletd.
### Examples
```javascript
const cli = new FactomCli({
factomd: {
host: 'api.factomd.net',
port: 443,
protocol: 'https'
},
walletd: {
host: 'localhost',
user: 'paul',
password: 'pass'
}
});
```
### add
[src/factom-cli.js:161-168][276]
Add an Entry/Chain or a collection of either of those to the Factom blockchain. Performs both commits and reveals.
#### Parameters
* `obj` **([Chain][277] | [Array][271]<[Chain][277]> | [Entry][278] | [Array][271]<[Entry][278]>)** Entry/Chain or array of Entry/Chain to add.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** (optional, default `{}`)
* `options.commitTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.revealTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.concurrency` **[number][258]** Only if the obj argument is an iterable. Limits the number of concurrent Promises adding entries/chains. (optional, default `200`)
* `options.skipFundValidation` **[boolean][261]** Skip the validation that the EC address holds enough Entry Credits to pay the commits. (optional, default `false`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **([Promise][280]<{txId: [string][260], repeatedCommit: [boolean][261], chainId: [string][260], entryHash: [string][260]}> | [Promise][280]<[Array][271]<{txId: [string][260], repeatedCommit: [boolean][261], chainId: [string][260], entryHash: [string][260]}>>)** Transaction ID (commit), if it is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]), chain id and entry hash.
It is an array of such object if the input was an iterable of Entry or Chain.
### addChain
[src/factom-cli.js:186-193][282]
Add a Chain to the Factom blockchain. Performs both commit and reveal.
#### Parameters
* `chain` **[Chain][277]** Chain to add.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** (optional, default `{}`)
* `options.commitTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.revealTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.skipFundValidation` **[boolean][261]** Skip the validation that the EC address holds enough Entry Credits to pay the commit. (optional, default `false`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<{txId: [string][260], repeatedCommit: [boolean][261], chainId: [string][260], entryHash: [string][260]}>** Transaction ID (commit), if it is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]), chain id and entry hash.
### addChains
[src/factom-cli.js:212-219][283]
Add a collection of Chains to the Factom blockchain. Performs both commits and reveals.
#### Parameters
* `chains` **[Array][271]<[Chain][277]>** Iterable of Chains to add.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** (optional, default `{}`)
* `options.commitTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.revealTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.concurrency` **[number][258]** Only if the obj argument is an iterable. Limits the number of concurrent Promises adding entries/chains. (optional, default `200`)
* `options.skipFundValidation` **[boolean][261]** Skip the validation that the EC address holds enough Entry Credits to pay the commits. (optional, default `false`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<[Array][271]<{txId: [string][260], repeatedCommit: [boolean][261], chainId: [string][260], entryHash: [string][260]}>>** Transaction ID (commit), if it is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]), chain id and entry hash.
### addEntries
[src/factom-cli.js:263-270][284]
Add a collection of Entries to the Factom blockchain. Performs both commits and reveals.
#### Parameters
* `entries` **[Array][271]<[Entry][278]>** Iterable of Entries to add.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** (optional, default `{}`)
* `options.commitTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.revealTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.concurrency` **[number][258]** Only if the obj argument is an iterable. Limits the number of concurrent Promises adding entries/chains. (optional, default `200`)
* `options.skipFundValidation` **[boolean][261]** Skip the validation that the EC address holds enough Entry Credits to pay the commits. (optional, default `false`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<[Array][271]<{txId: [string][260], repeatedCommit: [boolean][261], chainId: [string][260], entryHash: [string][260]}>>** Transaction ID (commit), if it is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]), chain id and entry hash.
### addEntry
[src/factom-cli.js:237-244][285]
Add an Entry to the Factom blockchain. Performs both commit and reveal.
#### Parameters
* `entry` **[Entry][278]** Entry to add.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** (optional, default `{}`)
* `options.commitTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.revealTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.skipFundValidation` **[boolean][261]** Skip the validation that the EC address holds enough Entry Credits to pay the commit. (optional, default `false`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<{txId: [string][260], repeatedCommit: [boolean][261], chainId: [string][260], entryHash: [string][260]}>** Transaction ID (commit), if it is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]), chain id and entry hash.
### chainExists
[src/factom-cli.js:355-357][286]
Check if a chain exists.
#### Parameters
* `chainId` **[string][260]** Chain ID to check.
Returns **[Promise][280]<[boolean][261]>**
### commit
[src/factom-cli.js:54-61][287]
Commit an Entry or a Chain.
#### Parameters
* `obj` **([Entry][278] | [Chain][277])** Entry or Chain to commit.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** Commit options. (optional, default `{}`)
* `options.ackTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<{txId: [string][260], repeatedCommit: [boolean][261]}>** Transaction ID and if this is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]). If repeatedCommit is true, txId is undefined.
### commitChain
[src/factom-cli.js:77-84][288]
Commit a Chain.
#### Parameters
* `chain` **[Chain][277]** Chain to commit.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** Commit options. (optional, default `{}`)
* `options.ackTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<{txId: [string][260], repeatedCommit: [boolean][261]}>** Transaction ID and if this is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]). If repeatedCommit is true, txId is undefined.
### commitEntry
[src/factom-cli.js:100-107][289]
Commit an Entry.
#### Parameters
* `entry` **[Entry][278]** Entry to commit.
* `ecAddress` **[string][260]** Entry Credit address that pays for the commit, either private (Es) or public (EC).
If a public address is passed, the private key must either be stored in factom-walletd or a sign function must be provided as part of the options.
* `options` **[Object][257]?** Commit options. (optional, default `{}`)
* `options.ackTimeout` **[number][258]** Time to wait in seconds for the commit ack. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.sign` **function ([Buffer][279], [string][260]): ([Buffer][279] | [string][260] | [Promise][280]<([Buffer][279] | [string][260])>)?** Signing function.
Takes as input the data to sign with the EC public key paying for the commmit
and should return its signature as a Buffer or a hex encoded string (or a Promise of those).
The returned signature must have been made by the private key corresponding to the ecAddress argument.
Returns **[Promise][280]<{txId: [string][260], repeatedCommit: [boolean][261]}>** Transaction ID and if this is a repeated commit ({@link [https://docs.factom.com/api#repeated-commit}][281]). If repeatedCommit is true, txId is undefined.
### createEntryCreditPurchaseTransaction
[src/factom-cli.js:439-448][290]
Create a transaction to convert Factoids to Entry Credit.
#### Parameters
* `originAddress` **[string][260]** Private or public Factoid address origin of the funds. If a public address is provided (FA) the corresponding private address must be stored in factom-walletd.
* `recipientAddress` **[string][260]** Public Entry Credit address to receive the ECs.
* `ecAmount` **[number][258]** Amount of Entry Credit (EC) to purchase.
* `fees` **[number][258]?** Value to override fees of the transaction (if not specified the library computes the lowest acceptable fee).
Returns **[Promise][280]<[Transaction][291]>**
### createFactoidTransaction
[src/factom-cli.js:419-428][292]
Create a single input single output (SISO) Factoid transaction.
#### Parameters
* `originAddress` **[string][260]** Private or public Factoid address origin of the funds. If a public address is provided (FA) the corresponding private address must be stored in factom-walletd.
* `recipientAddress` **[string][260]** Public Factoid address receiving the funds.
* `amount` **[number][258]** Amount to transfer in factoshis (10^-8 Factoids).
* `fees` **[number][258]?** Value to override fees of the transaction (if not specified the library computes the lowest acceptable fee).
Returns **[Promise][280]<[Transaction][291]>**
### factomdApi
[src/factom-cli.js:498-500][293]
Make a direct call to factomd API. See [https://docs.factom.com/api#factomd-api][294].
#### Parameters
* `method` **[string][260]** Factomd API method name.
* `params` **[Object][257]?** The object that the factomd API is expecting.
* `requestConfig` **[Object][257]?** Request configuration.
* `requestConfig.timeout` **[number][258]?** Timeout in milliseconds for the request. Override the timeout set at the instance level.
* `requestConfig.retry` **[Object][257]?** Retry strategy. For the detail of the options see [https://github.com/tim-kos/node-retry#retrytimeoutsoptions][295].
Override the retry strategy set at the instance level.
Returns **[Promise][280]<[Object][257]>** Factomd API response.
### getAdminBlock
[src/factom-cli.js:553-555][296]
Get an admin block by keyMR or height.
#### Parameters
* `arg` **([string][260] | [number][258])** Either KeyMR (string) or height (number) of the admin block.
Returns **[Promise][280]<[AdminBlock][297]>**
### getAllEntriesOfChain
[src/factom-cli.js:292-294][298]
Get all the entries of a given chain.
#### Parameters
* `chainId` **[string][260]** Chain ID of the chain to retrieve all the entries from.
Returns **[Promise][280]<[Array][271]<[Entry][278]>>** Array of entries ordered from the oldest to the newest.
### getBalance
[src/factom-cli.js:345-347][299]
Get the balance of an Entry Credit or Factoid address.
#### Parameters
* `address` **[string][260]** Any type of address, FCT or EC, public or private.
Returns **[Promise][280]<[number][258]>** Balance of EC or FCT. In the case of FCT the balance is in factoshis (10^-8 factoids).
### getChainHead
[src/factom-cli.js:304-306][300]
Get the head of a given chain.
#### Parameters
* `chainId` **[string][260]** Chain ID.
Returns **[Promise][280]<{keyMR: [string][260], chainInProcessList: [boolean][261]}>** result - keymr of the head of the chain.
chainInProcessList indicates if there is an Entry Block for that chain currently in the process list.
If this is the case that would indicate that the head of that chain will change at the next block.
### getDirectoryBlock
[src/factom-cli.js:543-545][301]
Get a directory block by keyMR or height.
#### Parameters
* `arg` **([string][260] | [number][258])** Either KeyMR (string) or height (number) of the directory block.
Returns **[Promise][280]<[DirectoryBlock][302]>**
### getDirectoryBlockHead
[src/factom-cli.js:533-535][303]
Return latest directory block saved.
Returns **[Promise][280]<[DirectoryBlock][302]>**
### getEntry
[src/factom-cli.js:314-316][304]
Get entry by hash (returned Entry does not contain an [EntryBlockContext][208] and a timestamp). See [FactomCli#getEntryWithBlockContext][305].
#### Parameters
* `entryHash` **[string][260]** Hash of the entry to query.
Returns **[Promise][280]<[Entry][278]>** Entry that does not contain an [EntryBlockContext][208] and a timestamp).
### getEntryBlock
[src/factom-cli.js:583-585][306]
Get an entry block.
#### Parameters
* `keyMR` **[string][260]** KeyMR of the entry block.
Returns **[Promise][280]<[EntryBlock][307]>**
### getEntryCreditBlock
[src/factom-cli.js:563-565][308]
Get an entry credit block by keyMR or height.
#### Parameters
* `arg` **([string][260] | [number][258])** Either KeyMR (string) or height (number) of the entry credit block.
Returns **[Promise][280]<[EntryCreditBlock][309]>**
### getEntryCreditRate
[src/factom-cli.js:364-366][310]
Get the current entry credit rate. The rate is the number of factoshis (10^-8 Factoids) necessary to purchase 1 EC.
Returns **[Promise][280]<[number][258]>** Entry credit rate.
### getEntryWithBlockContext
[src/factom-cli.js:325-327][311]
Get entry by hash with its [EntryBlockContext][208] and timestamp.
Note that this method is more expensive than [FactomCli#getEntry][312] as it also has to retrieve the Entry Block data.
#### Parameters
* `entryHash` **[string][260]** Hash of the entry to query.
Returns **[Promise][280]<[Entry][278]>** Entry with its blockContext and timestamp populated.
### getFactoidBlock
[src/factom-cli.js:573-575][313]
Get a Factoid block by keyMR or height.
#### Parameters
* `arg` **([string][260] | [number][258])** Either KeyMR (string) or height (number) of the factoid block.
Returns **[Promise][280]<[FactoidBlock][314]>**
### getFirstEntry
[src/factom-cli.js:335-337][315]
Get the first entry of a chain. This methods has to rewind the entire chain which can be an expensive operation.
#### Parameters
* `chainId` **[string][260]** Chain ID to retrieve the first entry from.
Returns **[Promise][280]<[Entry][278]>** Entry with its blockContext and timestamp populated.
### getHeights
[src/factom-cli.js:524-526][316]
Return blockchain heights. For the explanation of the different heights see [https://docs.factom.com/api#heights][317].
Returns **[Promise][280]<{directoryBlockHeight: [number][258], leaderHeight: [number][258], entryBlockHeight: [number][258], entryHeight: [number][258]}>**
### getPrivateAddress
[src/factom-cli.js:280-282][318]
Retrieve the corresponding private address of any type of address from factom-walletd if necessary.
#### Parameters
* `address` **[string][260]** Any address (EC or FCT, public or private).
Returns **[Promise][280]<[string][260]>** Corresponding private address.
### getTransaction
[src/factom-cli.js:374-376][319]
Get Factoid transaction by id.
#### Parameters
* `txId` **[string][260]** Transaction id.
Returns **[Transaction][291]**
### reveal
[src/factom-cli.js:116-118][320]
Reveal an Entry or Chain.
#### Parameters
* `obj` **([Entry][278] | [Chain][277])** Entry or Chain to reveal.
* `revealAckTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
Returns **[Promise][280]<{chainId: [string][260], entryHash: [string][260]}>**
### revealChain
[src/factom-cli.js:127-129][321]
Reveal a Chain.
#### Parameters
* `chain` **[Chain][277]** Chain to reveal.
* `revealAckTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
Returns **[Promise][280]<{chainId: [string][260], entryHash: [string][260]}>**
### revealEntry
[src/factom-cli.js:138-140][322]
Reveal a Entry.
#### Parameters
* `entry` **[Entry][278]** Entry to reveal.
* `revealAckTimeout` **[number][258]** Time to wait in seconds for the reveal ack. If negative value, doesn't wait for ack. (optional, default `60`)
Returns **[Promise][280]<{chainId: [string][260], entryHash: [string][260]}>**
### rewindChainWhile
[src/factom-cli.js:389-391][323]
Rewind a chain entry by entry (newest to oldest) while a predicate is true.
#### Parameters
* `chainId` **[string][260]** Chain to rewind.
* `predicate` **function ([Entry][278])** Predicate of the while loop. Iteration stop if either the predicate is false or the end of the chain has been reached.
* `func` **function ([Entry][278])** Function to apply at each iteration.
#### Examples
```javascript
cli.rewindChainWhile('dab6c095c22ec6db1b0961fdb82d504a95f0a31467bb7df73cc793532b0e9ae3', (entry) => true, function(entry) {
// Do stuff with the entry
})
```
### sendTransaction
[src/factom-cli.js:406-408][324]
Send a Factoid transaction.
This method will throw if the transaction fees are too low given the current EC rate.
Note that by default this method also rejects a transaction over paying the minimum required fees by a factor 10 as it is most likely a user input error. This can be overriden with the force option.
#### Parameters
* `transaction` **[Transaction][291]**
* `options` **[Object][257]?**
* `options.timeout` **[number][258]** Time to wait in seconds for transaction acknowledgment before timing out. If negative value, doesn't wait for ack. (optional, default `60`)
* `options.force` **[boolean][261]** Set to true to bypass the checks of the transaction fee overpay and the minimum EC output amount. (optional, default `false`)
Returns **[Promise][280]<[string][260]>** Transaction ID.
### waitOnCommitAck
[src/factom-cli.js:458-460][325]
Wait until an acknowlegment is received from the network for a commit.
#### Parameters
* `txId` **[string][260]** Commit transaction ID.
* `timeout` **[number][258]** Wait time in seconds. (optional, default `60`)
Returns **[Promise][280]<[string][260]>** Status of the commit. See [https://docs.factom.com/api#ack][326].
### waitOnFactoidTransactionAck
[src/factom-cli.js:481-483][327]
Wait until an acknowlegment is received from the network for a Factoid transaction.
#### Parameters
* `txId` **[string][260]** Transaction ID.
* `timeout` **[number][258]** Wait time in seconds. (optional, default `60`)
Returns **[Promise][280]<[string][260]>** Status of the transaction. See [https://docs.factom.com/api#ack][326].
### waitOnRevealAck
[src/factom-cli.js:470-472][328]
Wait until an acknowlegment is received from the network for a reveal.
#### Parameters
* `hash` **[string][260]** Hash of the revealed entry.
* `chainId` **[string][260]** Chain ID of the revealed entry.
* `timeout` **[number][258]** Wait time in seconds. (optional, default `60`)
Returns **[Promise][280]<[string][260]>** Status of the reveal. See [https://docs.factom.com/api#ack][326].
### walletdApi
[src/factom-cli.js:513-515][329]
Make a direct call to factom-walletd API. See [https://docs.factom.com/api#factom-walletd-api][330].
#### Parameters
* `method` **[string][260]** Walletd API method name.
* `params` **[Object][257]?** The object that the walletd API is expecting.
* `requestConfig` **[Object][257]?** Request configuration.
* `requestConfig.timeout` **[number][258]?** Timeout in milliseconds for the request. Override the timeout set at the instance level.
* `requestConfig.retry` **[Object][257]?** Retry strategy. For the detail of the options see [https://github.com/tim-kos/node-retry#retrytimeoutsoptions][295].
Override the retry strategy set at the instance level.
Returns **[Promise][280]<[Object][257]>** Walletd API response.
## addressToKey
[src/addresses.js:141-151][331]
Extract the key contained in an address. Cannot be used with public FCT address as those contain a RCD hash and not a key (See [addressToRcdHash][95]).
### Parameters
* `address` **[string][260]** Any address, except public FCT address.
Returns **[Buffer][279]** Key contained in the address.
## addressToRcdHash
[src/addresses.js:158-163][332]
Extract the RCD hash from a public FCT address.
### Parameters
* `address` **[string][260]** Public FCT address.
Returns **[Buffer][279]** RCD hash.
## AdminBlock
[src/blocks.js:86-113][333]
Class representing an Admin block.
### Properties
* `backReferenceHash` **[string][260]** Back reference hash.
* `lookupHash` **[string][260]** Lookup hash.
* `directoryBlockHeight` **[number][258]** Directory block height.
* `previousBackReferenceHash` **[string][260]** Back reference hash of previous Admin block.
* `headerExpansionSize` **[number][258]** Header expansion size.
* `headerExpansionArea` **[string][260]** Header expansion area.
* `bodySize` **[number][258]** Size of the body.
* `entries` **[Object][257]** Admin entries. Each entry has its own type (can be identified either by its adminId (number) or its adminCode (string)).
### getEntriesOfTypes
[src/blocks.js:109-112][334]
Return all the admin entries for given types.
#### Parameters
* `types` **...([number][258] | [string][260])** A sequence of either numbers representing an adminId or strings representing an adminCode.
Returns **[Object][257]** Admin entries.
## EntryBuilder
[src/entry.js:197-289][335]
Class to build an [Entry][127]
### Parameters
* `entry` **([Entry][278] | [Object][257])?** Optional entry to use to initialize the attributes of the builder.
### blockContext
[src/entry.js:277-280][336]
Set block context. This method is used internally by the library to populate a block context,
regular users should not have to use this.
#### Parameters
* `blockContext` **[EntryBlockContext][337]**
Returns **[EntryBuilder][338]** EntryBuilder instance.
### build
[src/entry.js:286-288][339]
Build the Entry.
Returns **[Entry][278]** Built entry.
### chainId
[src/entry.js:230-235][340]
Set chain ID.
#### Parameters
* `chainId` **([string][260] | [Buffer][279])** Chain ID.
* `enc` **[string][260]** Encoding of the chainId if it is a string. (optional, default `hex`)
Returns **[EntryBuilder][338]** EntryBuilder instance.
### content
[src/entry.js:218-223][341]
Set content.
#### Parameters
* `content` **([string][260] | [Buffer][279])** | Content.
* `enc` **[string][260]** Encoding of the content if it is a string. (optional, default `hex`)
Returns **[EntryBuilder][338]** EntryBuilder instance.
### extId
[src/entry.js:254-259][342]
Add an external ID.
#### Parameters
* `extId` **([string][260] | [Buffer][279])** External ID.
* `enc` **[string][260]** Encoding of the external id if it is a string. (optional, default `hex`)
Returns **[EntryBuilder][338]** EntryBuilder instance.
### extIds
[src/entry.js:242-247][343]
Set external IDs.
#### Parameters
* `extIds` **([Array][271]<[string][260]> | [Array][271]<[Buffer][279]>)** External IDs.
* `enc` **[string][260]** Encoding of the external ids if they are strings. (optional, default `hex`)
Returns **[EntryBuilder][338]** EntryBuilder instance.
### timestamp
[src/entry.js:266-269][344]
Set the timestamp for the entry commit.
If not set the library will use Date.now() as the commit timestamp.
#### Parameters
* `timestamp` **[number][258]** Timestamp in milliseconds.
Returns **[EntryBuilder][338]** EntryBuilder instance.
## TransactionBuilder
[src/transaction.js:300-392][345]
Class to build a [Transaction][147].
### Parameters
* `transaction` **[Transaction][291]?** Optional transaction to use to initialize the attributes of the builder.
### build
[src/transaction.js:389-391][346]
Build the Transaction.
Returns **[Transaction][291]** Built transaction.
### input
[src/transaction.js:327-341][347]
Add an input to the transaction.
#### Parameters
* `fctAddress` **[string][260]** Factoid address.
User should provide a private address (Fs) to allow the signature of the transaction.
If a public address is provided the user will need to provide the RCD and signature using [TransactionBuilder#rcdSignature][348].
* `amount` **[number][258]** Amount in factoshis (10^-8 Factoids).
Returns **[TransactionBuilder][349]** TransactionBuilder instance.
### output
[src/transaction.js:350-359][350]
Add an output to the transaction. Both FCT and EC outputs are supported.
Please note that in case of an EC output, the amount is still in factoshis, it is not the number of Entry Credits.
#### Parameters
* `publicAddress` **[string][260]** Factoid or Entry Credit public address.
* `amount` **[number][258]** Amount in factoshis (10^-8 Factoids).
Returns **[TransactionBuilder][349]** TransactionBuilder instance.
### rcdSignature
[src/transaction.js:368-372][351]
Add a RCD and signature to the transaction. This is used only in the case of unsigned transactions (usefull for hardware wallets).
RCDs/signatures need to be added in the same order as their corresponding inputs.
#### Parameters
* `rcd` **[string][260]** RCD.
* `signature` **[string][260]** Signature.
Returns **[TransactionBuilder][349]** TransactionBuilder instance.
### timestamp
[src/transaction.js:380-383][352]
Set the transaction timestamp.
If not set the library will use Date.now() as the transaction timestamp.
#### Parameters
* `timestamp` **[number][258]** Timestamp in milliseconds.
Returns **[TransactionBuilder][349]** TransactionBuilder instance.
## Entry
[src/entry.js:26-187][353]
Class representing an Entry.
### Parameters
* `builder` **[EntryBuilder][338]**
### Properties
* `chainId` **[Buffer][279]** Chain ID.
* `extIds` **[Array][271]<[Buffer][279]>** External IDs.
* `content` **[Buffer][279]** Content.
* `timestamp` **[number][258]** Timestamp in milliseconds for the commit.
* `blockContext` **[EntryBlockContext][337]** Block context. This property is *not* populated when using the method getEntry.
### Examples
```javascript
const myEntry = Entry.builder()
.chainId('9107a308f91fd7962fecb321fdadeb37e2ca7d456f1d99d24280136c0afd55f2')
.extId('6d79206578742069642031') // If no encoding parameter is passed as 2nd argument, 'hex' is used as default
.extId('Some external ID', 'utf8')
.content('My new content', 'utf8')
.build();
```
### chainIdHex
[src/entry.js:43-45][354]
Returns **[string][260]** Chain ID of the entry as hex encoded string.
### contentHex
[src/entry.js:50-52][355]
Returns **[string][260]** Entry content as hex encoded string.
### ecCost
[src/entry.js:152-159][356]
Get Entry Credit cost of the entry.
Returns **[number][258]** EC cost of the entry.
### extIdsHex
[src/entry.js:57-59][357]
Returns **[Array][271]<[string][260]>** External ids as hex encoded strings.
### hash
[src/entry.js:116-119][358]
Get hash of the entry.
Returns **[Buffer][279]** Hash of the entry.
### hashHex
[src/entry.js:124-126][359]
Returns **[string][260]** Hash of the entry as hex encoded string.
### marshalBinary
[src/entry.js:131-139][360]
Returns **[Buffer][279]** Result of marshaling the entry.
### marshalBinaryHex
[src/entry.js:144-146][361]
Returns **[string][260]** Result of marshaling the entry as hex encoded string.
### payloadSize
[src/entry.js:74-76][362]
Get the entry payload size (excluding the header).
Returns **[number][258]** The entry payload size in bytes.
### rawDataSize
[src/entry.js:82-84][363]
Get the entry raw data size (payload size excluding the 2 byte overhead per extID).
Returns **[number][258]** The entry raw size in bytes.
### remainingFreeBytes
[src/entry.js:90-97][364]
Get the number of bytes that can be added to the entry for the same EC cost.
Returns **[number][258]** Remaining number of free bytes.
### remainingMaxBytes
[src/entry.js:103-110][365]
Get the number of bytes that can be added to the entry before hitting the maximum (10kb).
Returns **[number][258]** Maximum number of bytes that can still be added to the entry.
### size
[src/entry.js:65-68][366]
Get the entry size.
Returns **[number][258]** The entry size in bytes.
### toObject
[src/entry.js:165-177][367]
Convert to a JavaScript Object representation of the entry. Can be used as argument of [EntryBuilder][101].
Returns **[Object][257]** JavaScript object representing the entry.
### builder
[src/entry.js:184-186][368]
Entry builder static factory.
#### Parameters
* `entry` **[Entry][278]?** Optional entry to use to initialize the attributes of the builder.
Returns **[EntryBuilder][338]** A new EntryBuilder.
## Transaction
[src/transaction.js:86-272][369]
Class representing a Factoid transaction.
### Parameters
* `builder` **[TransactionBuilder][349]**
* `blockContext` **[TransactionBlockContext][370]?**
### Properties
* `id` **[string][260]** Transaction ID.
* `timestamp` **[number][258]** Timestamp in milliseconds.
* `inputs` **[Array][271]<[TransactionAddress][371]>** Inputs.
* `factoidOutputs` **[Array][271]<[TransactionAddress][371]>** Factoid outputs.
* `entryCreditOutputs` **[Array][271]<[TransactionAddress][371]>** Entry Credit outputs.
* `totalInputs` **[number][258]** Total amount of factoshis as input of this transaction.
* `totalFactoidOutputs` **[number][258]** Total amount of factoshis as factoid outputs of this transaction.
* `totalEntryCreditOutputs` **[number][258]** Total amount of factoshis as entry credit outputs of this transaction.
* `feesPaid` **[number][258]** Fees paid in this transaction.
* `blockContext` **[TransactionBlockContext][370]** Block context.
* `rcds` **[Array][271]<[Buffer][279]>** RCDs.
* `signatures` **[Array][271]<[Buffer][279]>** Signatures.
### Examples
```javascript
const transaction = Transaction.builder()
.input('Fs2w6VL6cwBqt6SpUyPLvdo9TK834gCr52Y225z8C5aHPAFav36X', 14000000)
.input('Fs2E6iXCLAKDiPqVtfxtuQCKsTe7o6DJFDnht1wST53s4ibtdu9f', 1010000 + fees)
.output('FA3syRxpYEvFFvoN4ZfNRJVQdumLpTK4CMmMUFmKGeqyTNgsg5uH', 5000000)
.output('FA24PAtyZWWVAPm95ZCVpwyY6RYHeCMTiZt2v4VQAY8aBXMUZteF', 10000000)
// Note that the line below is to buy Entry Credits (see the address type) and the amount is in Factoshis like other outputs:
// it is *not* the number of Entry Credits you are purchasing.
.output('EC2UFobcsWom2NvyNDN67Q8eTdpCQvwYe327ZeGTLXbYaZ56e3QR', 10000)
.build()
```
### computeEcRequiredFees
[src/transaction.js:211-244][372]
Compute the required Entry Credit fees.
#### Parameters
* `opts` **[Object][257]?** Extra options necessary to compute fees of an unsigned transaction.
Returns **[number][258]** Fees in Entry Credit.
### computeRequiredFees
[src/transaction.js:202-204][373]
Compute the required fees (minimum difference between inputs and outputs amounts) for the transaction (for a given EC rate).
#### Parameters
* `ecRate` **[number][258]** Entry Credit rate. See [FactomCli#getEntryCreditRate][374].
* `opts` **[Object][257]?** Extra options necessary to compute fees of an unsigned transaction.
Returns **[number][258]** Number of factoshis (10^-8 Factoids) required as fees for this transaction.
### isSigned
[src/transaction.js:183-185][375]
Check if the transaction is signed or not.
Returns **[boolean][261]** True if the transaction is signed.
### marshalBinary
[src/transaction.js:249-262][376]
Returns **[Buffer][279]** Result of marshaling the transaction.
### validateFees
[src/transaction.js:192-194][377]
Compute if the fees of the transaction are enough (for a given EC rate).
#### Parameters
* `