LivepeerJS SDK
A module for interacting with Livepeer's smart contracts. The SDK is a core
dependency of most LivepeerJS packages.
Table of Contents
Installation
yarn add @livepeer/sdk
Usage
Here's a code snippet showing instantiation and basic usage of the Livepeer SDK.
import LivepeerSDK from '@livepeer/sdk'
LivepeerSDK({ ... }).then(async (sdk) => {
const { rpc } = sdk
const tokens = await rpc.getTokenTotalSupply()
console.log(tokens)
})
To use with a testnet please instantiate with the following params:
const provider = "https://rinkeby.infura.io" #or your testnet of choice
const controllerAddress = "0x37dC71366Ec655093b9930bc816E16e6b587F968"
LivepeerSDK({ provider, controllerAddress }).then(async sdk => {
mycode...
})
The following section details the rpc API's function signatures and typedefs.
API
Table of Contents
module~exports
Livepeer SDK main module exports
default
Livepeer SDK factory function. Creates an instance of the Livepeer SDK -- an
object with useful methods for interacting with Livepeer protocol smart
contracts
Parameters
Examples
import LivepeerSDK from "@livepeer/sdk";
LivepeerSDK().then((sdk) => {
});
Returns
Promise<LivepeerSDK>
livepeer~rpc
"rpc" namespace of a Livepeer SDK instance
Examples
import LivepeerSDK from "@livepeer/sdk";
LivepeerSDK().then(({ rpc }) => {
});
getENSName
Gets the ENS name for an address. This is known as a reverse lookup.
Unfortunately, users must explicitly set their own resolver. So most of the
time, this method just returns an empty string More info here:
(https://docs.ens.domains/en/latest/userguide.html#reverse-name-resolution)
Parameters
address
string
address to look up an ENS name for
Examples
await rpc.getENSName("0xd34db33f...");
Returns
Promise<string>
getENSAddress
Gets the address for an ENS name
Parameters
name
string
ENS name to look up an address for
Examples
await rpc.getENSAddress("vitalik.eth");
Returns
Promise<string>
getBlock
Gets a block by number, hash, or keyword ('earliest' | 'latest')
Parameters
Examples
await rpc.getBlock('latest')
"number": string,
"hash": string,
"parentHash": string,
"nonce": string,
"sha3Uncles": string,
"logsBloom": string,
"transactionsRoot": string,
"stateRoot": string,
"receiptsRoot": string,
"miner": string,
"mixHash": string,
"difficulty": string,
"totalDifficulty": string,
"extraData": string,
"size": string,
"gasLimit": string,
"gasUsed": string,
"timestamp": number,
"transactions": Array<Transaction>,
"transactionsRoot": string,
"uncles": Array<Uncle>,
}
Returns
Promise<Block>
getEthBalance
Gets the ETH balance for an account
Parameters
addr
string
ETH account address
Examples
await rpc.getEthBalance("0xf00...");
Returns
Promise<string>
getUnbondingPeriod
Gets the unbonding period for transcoders
Examples
await rpc.getUnbondingPeriod();
Returns
Promise<string>
getNumActiveTranscoders
Gets the number of active transcoders
Examples
await rpc.getNumActiveTranscoders();
Returns
Promise<string>
getMaxEarningsClaimsRounds
Gets the maximum earnings for claims rounds
Examples
await rpc.getMaxEarningsClaimsRounds();
Returns
Promise<string>
getTotalBonded
Gets the total amount of bonded tokens
Examples
await rpc.getTotalBonded();
Returns
Promise<string>
getTokenTotalSupply
Gets the total supply of token (LTPU) available in the protocol
Examples
await rpc.getTokenTotalSupply();
Returns
Promise<string>
getTokenBalance
Gets a user's token balance (LPTU)
Parameters
addr
string
user's ETH address
Examples
await rpc.getTokenBalance("0xf00...");
Returns
Promise<string>
getTokenInfo
Gets general information about tokens
Parameters
addr
string
user's ETH address
Examples
await rpc.getTokenInfo();
Returns
Promise<TokenInfo>
transferToken
Transfers tokens (LPTU) from one account to another
Parameters
to
string
the account ETH address to send tokens toamount
string
the amount of token to send (LPTU)tx
TxConfig an object specifying the from
value of the
transaction (optional, default config.defaultTx
)
Examples
await rpc.transferToken("0xf00...", "10");
Returns
Promise<TxReceipt>
getFaucetAmount
The amount of LPT the faucet distributes when tapped
Examples
await rpc.getFaucetAmount();
Returns
Promise<string>
getFaucetWait
How often an address can tap the faucet (in hours)
Examples
await rpc.getFaucetWait();
Returns
Promise<string>
getFaucetNext
Next timestamp at which the given address will be allowed to tap the faucet
Parameters
addr
string
user's ETH address
Examples
await rpc.getFaucetNext();
Returns
Promise<string>
getFaucetInfo
Info about the state of the LPT faucet
Parameters
addr
string
user's ETH address
Examples
await rpc.getFaucetInfo("0xf00...");
Returns
Promise<FaucetInfo>
getInflation
Gets the per round inflation rate
Examples
await rpc.getInflation();
Returns
Promise<string>
getInflationChange
Gets the change in inflation rate per round until the target bonding rate is
achieved
Examples
await rpc.getInflationChange();
Returns
Promise<string>
getDelegatorStatus
The delegator status of the given address
Parameters
addr
string
user's ETH address
Examples
await rpc.getDelegatorStatus("0xf00...");
Returns
Promise<string>
getDelegator
General info about a delegator
Parameters
addr
string
user's ETH address
Examples
await rpc.getDelegator("0xf00...");
Returns
Promise<Delegator>
rebond
Rebonds LPT from an address
Parameters
unbondingLockId
numbertx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.rebond(0);
Returns
Promise<TxReceipt>
rebondWithHint
Rebonds LPT from an address with hint
Parameters
unbondingLockId
numbernewPosPrev
stringnewPosNext
stringtx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.rebondWithHint(0, "0x", "0x");
Returns
Promise<TxReceipt>
rebondFromUnbonded
Rebonds LPT from an address
Parameters
to
stringunbondingLockId
numbertx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.rebondFromUnbonded("0x", 1);
Returns
Promise<TxReceipt>
rebondFromUnbondedWithHint
Rebonds LPT from an address with hint
Parameters
to
stringunbondingLockId
numbernewPosPrev
stringnewPosNext
stringtx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.rebondFromUnbondedWithHint("0x", 1, "0x", "0x");
Returns
Promise<TxReceipt>
getPendingStake
Get a delegator's pending stake
Parameters
addr
string
user's ETH addressendRound
string
The last round to compute pending stake from
Examples
await rpc.getPendingStake("0xf00...");
Returns
Promise<string>
getPendingFees
Get a delegator's pending fees
Parameters
addr
string
user's ETH addressendRound
string
The last round to compute pending fees from
Examples
await rpc.getPendingFees("0xf00...");
Returns
Promise<string>
getTranscoderIsActive
Whether or not the transcoder is active
Parameters
addr
string
user's ETH address
Examples
await rpc.getTranscoderIsActive("0xf00...");
Returns
Promise<boolean>
getTranscoderStatus
Gets the status of a transcoder
Parameters
addr
string
user's ETH address
Examples
await rpc.getTranscoderStatus("0xf00...");
Returns
Promise<string>
getTranscoderTotalStake
Gets a transcoder's total stake
Parameters
addr
string
user's ETH address
Examples
await rpc.getTranscoderTotalStake("0xf00...");
Returns
Promise<string>
getTranscoderPoolMaxSize
Gets a transcoder's pool max size
Examples
await rpc.getTranscoderPoolMaxSize();
Returns
Promise<string>
getTranscoder
Gets info about a transcoder
Parameters
addr
string
user's ETH address
Examples
await rpc.getTranscoder("0xf00...");
Returns
Promise<Transcoder>
getTranscoders
Gets transcoders
Examples
await rpc.getTranscoders();
Returns
Array<Transcoder>
getProtocolPaused
Whether the protocol is paused
Examples
await rpc.getProtocolPaused();
Returns
Promise<boolean>
getProtocol
Gets the protocol
Examples
await rpc.getProtocol()
paused
totalTokenSupply
totalBondedToken
targetBondingRate
transcoderPoolMaxSize
maxEarningsClaimsRounds
}
Returns
Promise<Protocol>
getRoundLength
Gets the length of a round (in blocks)
Examples
await rpc.getRoundLength();
Returns
Promise<string>
getRoundsPerYear
Gets the estimated number of rounds per year
Examples
await rpc.getRoundsPerYear();
Returns
Promise<string>
getCurrentRound
Gets the number of the current round
Examples
await rpc.getCurrentRound();
Returns
Promise<string>
getCurrentRoundIsInitialized
Whether or not the current round is initalized
Examples
await rpc.getCurrentRoundIsInitialized();
Returns
Promise<boolean>
getCurrentRoundStartBlock
The block at which the current round started
Examples
await rpc.getCurrentRoundStartBlock();
Returns
Promise<string>
getLastInitializedRound
The previously intitialized round
Examples
await rpc.getLastInitializedRound();
Returns
Promise<string>
getCurrentRoundInfo
Gets general information about the rounds in the protocol
Examples
await rpc.getCurrentRoundInfo();
Returns
Promise<RoundInfo>
tapFaucet
Gets LPT from the faucet
Parameters
tx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.tapFaucet("1337");
Returns
Promise<TxReceipt>
initializeRound
Initializes the round
Parameters
tx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.initializeRound();
Returns
Promise<TxReceipt>
createPoll
Creates a poll
Parameters
proposal
string
The IPFS multihash for the proposaltx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.createPoll("Qm...");
Returns
Promise<TxReceipt>
getPollCreatorAllowance
Get PollCreator transfer allowance
Parameters
addr
string
user's ETH addresstx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.getPollCreatorAllowance("0x...");
Returns
Promise<TxReceipt>
getBondingManagerAllowance
Get BondingManager transfer allowance
Parameters
addr
string
user's ETH addresstx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.getBondingManagerAllowance("0x...");
Returns
Promise<TxReceipt>
vote
Creates a poll
Parameters
pollAddress
string
poll contract addresschoiceId
int vote (0 = yes, 1 = no)tx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.initializeRound();
Returns
Promise<TxReceipt>
claimEarnings
Claims token and eth earnings from the sender's lastClaimRound + 1
through a
given endRound
Parameters
endRound
string
the round to claim earnings untiltx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.claimEarnings();
Returns
string
bondWithHint
Bonds to a transcoder with hint
Parameters
amount
stringto
stringoldDelegateNewPosPrev
stringoldDelegateNewPosNext
stringcurrDelegateNewPosPrev
stringcurrDelegateNewPosNext
stringtx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.bondWithHint("100", "0x", "0x", "0x", "0x", "0x");
Returns
Promise<TxReceipt>
estimateGas
Gets the estimated amount of gas to be used by a smart contract method.
Parameters
contractName
string
: name of contract containing method you wish to find gas price for.
methodName: name of method on contract. methodArgs: array of argument to be
passed to the contract in specified order. tx: (optioanl){ from: address -
0x..., gas: number, value: (optional) number or string containing number }methodName
stringmethodArgs
Arraytx
(optional, default config.defaultTx
)
Examples
await rpc.estimateGas("BondingManager", "bond", [10, "0x00....."]);
Returns
Promise<number>
containing estimated gas price
unbond
Unbonds LPT from an address
Parameters
amount
stringtx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.unbond(amount);
Returns
Promise<TxReceipt>
unbondWithHint
Unbonds LPT from an address with hint
Parameters
amount
stringnewPosPrev
stringnewPosNext
stringtx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.unbondWithHint("100", "0x", "0x");
Returns
Promise<TxReceipt>
setupTranscoder
Sets transcoder parameters
Parameters
rewardCut
string
the block reward cut you wish to setfeeShare
string
the fee share you wish to setpricePerSegment
string
the price per segment you wish to settx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.setupTranscoder("10", "10", "5");
Returns
Promise<TxReceipt>
getTargetBondingRate
Get target bonding rate
Examples
await rpc.getTargetBondingRate();
Returns
Promise<string>
withdrawStake
Withdraws earned token (Transfers a sender's delegator bondedAmount
to their
tokenBalance
)
Parameters
unbondLockId
string?
the unbond lock idtx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.withdrawStake();
Returns TxReceipt
withdrawStakeWithUnbondLock
Withdraws earned token (Transfers a sender's delegator bondedAmount
to their
tokenBalance
)
Parameters
unbondlock
{id:
string,
amount:
string,
withdrawRound:
string}tx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.withdrawStakeWithUnbondLock(unbondlock);
Returns TxReceipt
withdrawFees
Withdraws earned fees (Transfers a sender's delegator fees
to their
ethBalance
)
Parameters
tx
TxConfig an object specifying the from
and gas
values of the transaction (optional, default config.defaultTx
)
Examples
await rpc.withdrawFees();
Returns TxReceipt
getDelegatorUnbondingLocks
Get all the unbonding locks for a delegator
Parameters
addr
string
delegator's ETH address
Examples
await rpc.getDelegatorUnbondingLocks("0xf00...");
Returns
Promise<Array<UnbondingLock>>
getDelegatorUnbondingLock
Get an unbonding lock for a delegator
Parameters
addr
string
delegator's ETH addressunbondingLockId
string
unbonding lock ID
Examples
await rpc.getDelegatorUnbondingLock("0xf00...", 1);
Returns
Promise<UnbondingLock>
ABIPropDescriptor
ABI property descriptor
Type:
Object
Properties
ContractArtifact
Mostly "truffle
-style" ABI artifacts but no bytecode/network properties
required
Type:
Object
Properties
LivepeerSDKOptions
SDK configuration options
Type:
Object
Properties
controllerAddress
string?
The address of the delpoyed Controller contractprovider
string?
The ETH http provider for rpc methodsgas
number?
the amount of gas to include with transactions by defaultartifacts
Object<string,
ContractArtifact> an object containing contract name ->
ContractArtifact mappingsprivateKeys
Object<string,
string>
an object containing public -> private key mappings. Should be specified if
using the SDK for transactions without MetaMask (via CLI, etc)account
(string
|
number)
the account that will be used for transacting and data-fetching. Can be one of
the publicKeys specified in the privateKeys
option or an index of an account
available via MetaMask
LivepeerSDK
An object containing contract info and utility methods for interacting with the
Livepeer protocol's smart contracts
Type:
Object
Properties
config
Object<string,
any> this prop is mostly for debugging purposes and could change a lot in
the future. Currently, it contains the following props: abis
, accounts
,
contracts
, defaultTx
, eth
constants
Object<string,
any> Exposes some constant values. Currently, it contains the following
props: ADDRESS_PAD
, DELEGATOR_STATUS
, EMPTY_ADDRESS
,
TRANSCODER_STATUS
, VIDEO_PROFILES
, VIDEO_PROFILE_ID_SIZE
create
Function
same as the createLivepeerSDK
functionevents
Object<string,
Object>
Object mapping an event name -> contract event descriptor objectrpc
Object<string,
Function>
contains all of the rpc methods available for interacting with the Livepeer
protocolutils
Object<string,
Function>
contains utility methods. Mostly here just because. Could possibly be removed
or moved into its own module in the future
TokenInfo
An object containing the total token supply and a user's account balance.
Type:
Object
Properties
totalSupply
string
total supply of token available in the protocol (LPTU)balance
string
user's token balance (LPTU)
Protocol
A Protocol struct
Type:
Object
Properties
paused
boolean
the protocol paused or nottotalTokenSupply
string
total token supply for protocoltotalBondedToken
string
total bonded token for protocoltargetBondingRate
string
target bonding rate for protocoltranscoderPoolMaxSize
string
transcoder pool max size
TxReceipt
Transaction receipt
Type:
Object
Properties
transactionHash
string
the transaction hashtransactionIndex
BN the transaction indexblockHash
string
the transaction block hashblockNumber
BN the transaction block numbercumulativeGasUsed
BN the cumulative gas used in the transactiongasUsed
BN the gas used in the transactioncontractAddress
string
the contract address of the transaction methodlogs
Array<Log>
an object containing logs that were fired during the transaction
Log
An object representing a contract log
Type:
Object
Properties
logIndex
BN the log indexblockNumber
BN the log block numberblockHash
string
the log block hashtransactionHash
string
the log's transaction hashtransactionIndex
BN the log's transaction indexaddress
string
the log's addressdata
string
the log's datatopics
Array<string>
the log's topics
FaucetInfo
Information about the status of the LPT faucet
Type:
Object
Properties
amount
string
the amount distributed by the faucetwait
string
the faucet request cooldown timenext
string
the next time a valid faucet request may be made
Broadcaster
A Broadcaster struct
Type:
Object
Properties
address
string
the ETH address of the broadcasterdeposit
string
the amount of LPT the broadcaster has depositedwithdrawBlock
string
the next block at which a broadcaster may withdraw their deposit
Delegator
A Delegator struct
Type:
Object
Properties
allowance
string
the delegator's LivepeerToken approved amount for transferaddress
string
the delegator's ETH addressbondedAmount
string
The amount of LPTU a delegator has bondeddelegateAddress
string
the ETH address of the delegator's delegatedelegatedAmount
string
the amount of LPTU the delegator has delegatedfees
string
the amount of LPTU a delegator has collectedlastClaimRound
string
the last round that the delegator claimed reward and fee pool sharespendingFees
string
the amount of ETH the delegator has earned up to the current roundpendingStake
string
the amount of token the delegator has earned up to the current roundstartRound
string
the round the delegator becomes bonded and delegated to its delegatestatus
string
the delegator's statuswithdrawableAmount
string
the amount of LPTU a delegator can withdrawwithdrawRound
string
the round the delegator can withdraw its stakenextUnbondingLockId
string
the next unbonding lock ID for the delegator
Transcoder
A Transcoder struct
Type:
Object
Properties
active
boolean
whether or not the transcoder is activeaddress
string
the transcoder's ETH addressrewardCut
string
% of block reward cut paid to transcoder by a delegatorfeeShare
string
% of fees paid to delegators by transcoderlastRewardRound
string
last round that the transcoder called rewardpendingRewardCut
string
pending block reward cut for next round if the transcoder is activependingFeeShare
string
pending fee share for next round if the transcoder is activependingPricePerSegment
string
pending price per segment for next round if the transcoder is activepricePerSegment
string
price per segment for a stream (LPTU)status
string
the transcoder's statustotalStake
string
total tokens delegated toward a transcoder (including their own)
UnbondingLock
An UnbondingLock struct
Type:
Object
Properties
id
string
the unbonding lock IDdelegator
string
the delegator's ETH addressamount
string
the amount of tokens being unbondedwithdrawRound
string
the round at which unbonding period is over and tokens can be withdrawn
RoundInfo
An object containing information about the current round
Type:
Object
Properties
id
string
the number of the current roundinitialized
boolean
whether or not the current round is initializedstartBlock
string
the start block of the current roundlastInitializedRound
string
the last round that was initialized prior to the currentlength
string
the length of rounds
Block
An object containing information about an Ethereum block
Type:
Object
Properties
number
string
block numberhash
string
block hashparentHash
string
parent has of the blocknonce
string
block noncesha3Uncles
string
block sha3 uncleslogsBloom
string
logss bloom for the blocktransactionsRoot
string
block transaction root hashstateRoot
string
block state root hashreceiptsRoot
string
block receipts root hashminer
string
block miner hashmixHash
string
block mixHashdifficulty
string
difficulty inttotalDifficulty
string
total difficulty intextraData
string
hash of extra datasize
string
block sizegasLimit
string
block gas limitgasUsed
string
gas used in blocktimestamp
number
block timestamptransactions
string
block transactions hashuncles
string
block uncles hashtransactions
Array<Transaction>
transactions in the blocktransactionsRoot
string
root transaction hashuncles
Array<Uncle>
block uncles
TxConfig
Transaction config object
Type:
Object
Properties
from
string
the ETH account address to sign the transaction fromgas
number
the amount of gas to include in the transaction