
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
livepeer-sdk-test
Advanced tools
A module for interacting with Livepeer's smart contracts. The SDK is a core dependency of most LivepeerJS packages.
A module for interacting with Livepeer's smart contracts. The SDK is a core dependency of most LivepeerJS packages.
yarn add @livepeer/sdk
Here's a code snippet showing instantiation and basic usage of the Livepeer SDK.
import LivepeerSDK from '@livepeer/sdk'
// Or if you prefer require
// const { LivepeerSDK } = require('@livepeer/sdk')
//
// First, call the SDK factory function
// pass it any configuration options
LivepeerSDK({ ... }).then(async (sdk) => {
// Once initialized, you can access the methods under the `rpc` namespace
const { rpc } = sdk
// For example, you can get the total supply of Livepeer Tokens like so
const tokens = await rpc.getTokenTotalSupply()
console.log(tokens)
// => string representation of some absurdly high number, maybe "9999999999999999999999" or something like that :)
})
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.
Livepeer SDK main module exports
Livepeer SDK factory function. Creates an instance of the Livepeer SDK -- an object with useful methods for interacting with Livepeer protocol smart contracts
Parameters
opts LivepeerSDKOptions SDK configuration optionsExamples
// Here we're naming the default export "LivepeerSDK"
import LivepeerSDK from '@livepeer/sdk'
// Call the factory function and await its Promise
LivepeerSDK().then(sdk => {
// Your Livepeer SDK instance is now ready to use
})
Returns Promise<LivepeerSDK>
"rpc" namespace of a Livepeer SDK instance
Examples
import LivepeerSDK from '@livepeer/sdk'
LivepeerSDK().then(({ rpc }) => {
// Here, we're destructuring the sdk to expose only its rpc namespace
// Now, you you are able call rpc.<method-name>()
// All rpc method yield Promises. Their usage is further explained below.
})
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 forExamples
await rpc.getENSName('0xd34db33f...')
// => string
Gets the address for an ENS name
Parameters
name string ENS name to look up an address forExamples
await rpc.getENSAddress('vitalik.eth')
// => string
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>,
}
Gets the ETH balance for an account
Parameters
addr string ETH account addressExamples
await rpc.getEthBalance('0xf00...')
// => string
Gets the unbonding period for transcoders
Examples
await rpc.getUnbondingPeriod()
// => string
Gets the number of active transcoders
Examples
await rpc.getNumActiveTranscoders()
// => string
Gets the maximum earnings for claims rounds
Examples
await rpc.getMaxEarningsClaimsRounds()
// => string
Gets the total amount of bonded tokens
Examples
await rpc.getTotalBonded()
// => string
Gets the total supply of token (LTPU) available in the protocol
Examples
await rpc.getTokenTotalSupply()
// => string
Gets a user's token balance (LPTU)
Parameters
addr string user's ETH addressExamples
await rpc.getTokenBalance('0xf00...')
// => string
Gets general information about tokens
Parameters
addr string user's ETH addressExamples
await rpc.getTokenInfo()
// => TokenInfo { totalSupply: string, balance: string }
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 and gas values of the transaction (optional, default config.defaultTx)Examples
await rpc.transferToken('0xf00...', '10')
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
The amount of LPT the faucet distributes when tapped
Examples
await rpc.getFaucetAmount()
// => string
How often an address can tap the faucet (in hours)
Examples
await rpc.getFaucetWait()
// => string
Next timestamp at which the given address will be allowed to tap the faucet
Parameters
addr string user's ETH addressExamples
await rpc.getFaucetNext()
// => string
Info about the state of the LPT faucet
Parameters
addr string user's ETH addressExamples
await rpc.getFaucetInfo('0xf00...')
// => FaucetInfo {
// amount: string,
// wait: string,
// next: string,
// }
Returns Promise<FaucetInfo>
Gets the per round inflation rate
Examples
await rpc.getInflation()
// => string
Gets the change in inflation rate per round until the target bonding rate is achieved
Examples
await rpc.getInflationChange()
// => string
Info about a broadcaster
Parameters
addr string user's ETH addressExamples
await rpc.getBroadcaster('0xf00...')
// => Broadcaster {
// address: string,
// deposit: string,
// withdrawBlock: string,
// }
Returns Promise<Broadcaster>
The delegator status of the given address
Parameters
addr string user's ETH addressExamples
await rpc.getDelegatorStatus('0xf00...')
// => 'Pending' | 'Bonded' | 'Unbonded'
The delegator's stake
Parameters
addr string user's ETH addressExamples
await rpc.getDelegatorStake('0xf00...')
// => string
General info about a delegator
Parameters
addr string user's ETH addressExamples
await rpc.getDelegator('0xf00...')
// => Delegator {
// allowance: string,
// address: string,
// bondedAmount: string,
// delegateAddress: string,
// delegateAmount: string,
// fees: string,
// lastClaimRound: string,
// pendingFees: string,
// pendingStake: string,
// startRound: string,
// status: 'Pending' | 'Bonded' | 'Unbonding' | 'Unbonded',
// withdrawRound: string,
// nextUnbondingLockId: string,
// }
Whether or not the transcoder is active
Parameters
addr string user's ETH addressExamples
await rpc.getTranscoderIsActive('0xf00...')
// => boolean
Gets the status of a transcoder
Parameters
addr string user's ETH addressExamples
await rpc.getTranscoderStatus('0xf00...')
// => 'NotRegistered' | 'Registered'
Gets a transcoder's total stake
Parameters
addr string user's ETH addressExamples
await rpc.getTranscoderTotalStake('0xf00...')
// => string
Gets a transcoder's pool max size
Examples
await rpc.getTranscoderPoolMaxSize()
// => string
Gets info about a transcoder
Parameters
addr string user's ETH addressExamples
await rpc.getTranscoder('0xf00...')
// => Transcoder {
// active: boolean,
// address: string,
// rewardCut: string,
// feeShare: string,
// lastRewardRound: string,
// pendingRewardCut string,
// pendingFeeShare: string,
// pendingPricePerSegment: string,
// pricePerSegment: string,
// status: 'NotRegistered' | 'Registered',
// totalStake: string,
// }
Returns Promise<Transcoder>
Gets transcoders
Examples
await rpc.getTranscoders()
// => Array<Transcoder>
Returns Array<Transcoder>
Whether the protocol is paused
Examples
await rpc.getProtocolPaused()
// => boolean
Gets the protocol
Examples
await rpc.getProtocol()
// => Protocol {
paused
totalTokenSupply
totalBondedToken
targetBondingRate
transcoderPoolMaxSize
}
Gets the length of a round (in blocks)
Examples
await rpc.getRoundLength()
// => string
Gets the estimated number of rounds per year
Examples
await rpc.getRoundsPerYear()
// => string
Gets the number of the current round
Examples
await rpc.getCurrentRound()
// => string
Whether or not the current round is initalized
Examples
await rpc.getCurrentRoundIsInitialized()
// => boolean
The block at which the current round started
Examples
await rpc.getCurrentRoundStartBlock()
// => string
The previously intitialized round
Examples
await rpc.getLastInitializedRound()
// => string
Gets general information about the rounds in the protocol
Examples
await rpc.getCurrentRoundInfo()
// => RoundInfo {
// id: string,
// initialized: boolean,
// startBlock: string,
// lastInitializedRound: string,
// length: string,
// }
Total jobs that have been created
Examples
await rpc.getTotalJobs()
// => string
Verification rate for jobs
Examples
await rpc.getJobVerificationRate()
// => string
Verification period for jobs
Examples
await rpc.getJobVerificationPeriod()
// => string
Slashing period for jobs
Examples
await rpc.getJobVerificationSlashingPeriod()
// => string
Finder fee for jobs
Examples
await rpc.getJobFinderFee()
// => string
Gets general info about the state of jobs in the protocol
Examples
await rpc.getJobsInfo()
// => JobsInfo {
// total: string,
// verificationRate: string,
// verificationPeriod: string,
// verificationSlashingPeriod: string,
// finderFee: string,
// }
Gets a job by id
Parameters
id string the job idExamples
await rpc.getJob('1337')
// => Job {
// id: string,
// streamId: string,
// transcodingOptions: Array<JobProfile>
// transcoder: string,
// broadcaster: string,
// }
Gets a list of jobs
Parameters
$0 Object (optional, default {})
$0.to$0.from$0.blocksAgo (optional, default 100*10000)$0.filters ...anyExamples
await rpc.getJobs()
// => Array<Job>
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')
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
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()
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
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()
// => string
Returns string
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.....']
)
// => 33454
Returns Promise<number> containing estimated gas price
Unbonds LPT from an address
Parameters
tx TxConfig an object specifying the from and gas values of the transaction (optional, default config.defaultTx)Examples
await rpc.unbond()
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
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')
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
Get target bonding rate
Examples
await rpc.getTargetBondingRate()
// => string
Deposits ETH for broadcasting
Parameters
amount string amount of ETH to deposittx TxConfig an object specifying the from and gas values of the transaction (optional, default config.defaultTx)Examples
await rpc.deposit('100')
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
Withdraws deposited ETH
Parameters
tx TxConfig an object specifying the from and gas values of the transaction (optional, default config.defaultTx)Examples
await rpc.withdraw()
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
Withdraws earned token (Transfers a sender's delegator bondedAmount to their tokenBalance)
Parameters
tx TxConfig an object specifying the from and gas values of the transaction (optional, default config.defaultTx)Examples
await rpc.withdrawStake()
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
Returns TxReceipt
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()
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
Returns TxReceipt
Creates a job
Parameters
streamId string the stream id for the jobprofiles Array<string> a list of profiles to transcode the job into (optional, default [// default profiles 'P240p30fps4x3','P360p30fps16x9'])maxPricePerSegment string the maximum LPTU price the broadcaster is willing to pay per segmenttx TxConfig an object specifying the from and gas values of the transaction (optional, default config.defaultTx)Examples
await rpc.createJob('foo', [P240p30fps4x3', 'P360p30fps16x9'], '5')
// => TxReceipt {
// transactionHash: string,
// transactionIndex": BN,
// blockHash: string,
// blockNumber: BN,
// cumulativeGasUsed: BN,
// gasUsed: BN,
// contractAddress: string,
// logs: Array<Log {
// logIndex: BN,
// blockNumber: BN,
// blockHash: string,
// transactionHash: string,
// transactionIndex: string,
// address: string,
// data: string,
// topics: Array<string>
// }>
// }
Get an unbonding lock for a delegator
Parameters
Examples
await rpc.getDelegatorUnbondingLock('0xf00...', 1)
// => UnbondingLock {
// id: string,
// delegator: string,
// amount: string,
// withdrawRound: string
// }
Returns Promise<UnbondingLock>
ABI property descriptor
Type: Object
Properties
constants boolean is the method constant?inputs Array<{name: string, type: string}> the method paramsoutputs Array<{name: string, type: string}> method return valuespayable boolean is the method payable?stateMutability string type of state mutabilitytype string type of contract propertyMostly "truffle-style" ABI artifacts but no bytecode/network properties required
Type: Object
Properties
name string name of the contractabi Array<ABIPropDescriptor> lists info about contract propertiesSDK 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 MetaMaskAn 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, ethconstants 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_SIZEcreate 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 futureAn 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)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 transactionTransaction 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 transactionA 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 sizeInformation 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 madeA 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 depositA 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 delegatorA 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)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 withdrawnAn 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 roundsAn 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 unclesAn object containing overview information about the jobs in the protocol
Type: Object
Properties
total string the total number of jobs createdverificationRate boolean the verification rate for jobsverificationPeriod string the verification period for jobsverificationSlashingPeriod string the slashing period for jobsfinderFee string the finder fee for jobsA Job struct
Type: Object
Properties
jobId string the id of the jobstreamId string the job's stream idtranscodingOptions Array<TranscodingProfile> transcoding profilestranscoder string? the ETH address of the assigned transcoderbroadcaster string the ETH address of the broadcaster who created the jobAn object representing a contract log
Type: Object
Properties
FAQs
A module for interacting with Livepeer's smart contracts. The SDK is a core dependency of most LivepeerJS packages.
We found that livepeer-sdk-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.