utils sub-class
The following readme describes all the functions and their parameters exposed by the utils
class of the K2 SDK.
add0x function
This function can be used to append 0x
towards the start of a string to convert it into a hex string accepted by the contracts. If the input string already contains the 0x
, the function will return the string as is.
Input Parameters
data: string which needs to be appended by 0x
Using add0x function
Return Parameter
Returns hex string
remove0x function
This function removes 0x
from the beginning of a string. If the input string doesn’t contain 0x
, it will return the string as is.
Input Parameters
data: string to remove 0x
from
Using remove0x function
Return Parameter
Returns string without 0x
in the beginning.
generateLivenessReport function
This function can be used to generate a liveness reports of the software being run.
Input Parameters
middlewareAPI: API endpoint of the middleware
Using generateLivenessReport function
Return Parameter
Returns a liveness report. Here’s a sample liveness report:
getMiddlewareInfo function
This function can be used to get the info from the middleware endpoint.
Input Parameters
middlewareAPI: API endpoint of the middleware
Using getMiddlewareInfo function
Return Parameter
The function returns info related to the middleware API. Here’s an example of the info:
verifyReport function
Once the liveness or the corruption report has been generated, it needs to be verified before submitting it to the reporter registry. To verify the report, verifyReport
function should be used.
Input Parameters
middlewareAPI: API endpoint of the middleware
report: Liveness or the corruption report returned by the respective function
Using verifyReport function
Return Parameter
The function returns a verified report which contains the liveness report along with a signature valid for 20 minutes. Here’s how a verified report looks like:
verifyEffectiveBalance function
This function can be used to batch verify effective balance of a list of BLS public keys.
Input Parameters
blsPublicKeys: List of BLS public keys in string format
effectiveBalances: List of effective balance in string corresponding to each BLS public key
Using verifyEffectiveBalance function
Return Parameter
The function returns a list of verified effective balance report after it has been successfully verified and error otherwise.
readUsingMulticall function
Allows to read batch values from a contract in a single RPC call.
Input Parameters
targetContract: Address of the target contract in string format
allowFailure: Boolean. Set to true
to throw error if any one value is rejected by the contract
calldata: List of calldata in string
Using readUsingMulticall function
Return Parameter
Returns a list of response for each call data in the format:
The result will have to be decoded to correctly get all the values.
getEffectiveBalance function
Get effective balance of a BLS public key from the consensus layer.
Input Parameters
beaconNodeUrl: Beacon node URL string
blsPublicKey: BLS public key in string format to get effective balance of
Using getEffectiveBalance function
Return Parameter
Effective balance in numbers
generateCorruptionReport function
Generate corruption report from the data received from middleware API endpoint.
Input Parameters
middlewareAPI: API endpoint of the middleware
eventData: event data of the format CorruptionEventDataT
message: string message which needs to be mentioned in the report. Default value: ''
debtorOverride: optional debtor address. Can be left null
for the function to fetch debtor address from the middlewareAPI
Using generateCorruptionReport function
Return Parameter
Returns corruption report of the format:
claimEffectiveBalance function
Claim effective balance for all the BLS public keys delegated by the user.
Input Parameters
beaconNodeUrl: Beacon node URL in string
userAddress: user address in string
Using claimEffectiveBalance function
Return Parameter
Transaction hash
getClaimableKETHForNodeOperator function
Preview claimable effective balance for all the BLS public keys delegated by the user.
Input Parameters
userAddress: user address in string
Using getClaimableKETHForNodeOperator function
Return Parameter
List of claimable kETH in Big Numbers
getAllDelegetedBLSPublicKeysForNodeRunner function
Get a list of BLS public keys delegated by a node operator.
Input Parameters
nodeRunnerAddress: Address of the node runner in string
Using getAllDelegetedBLSPublicKeysForNodeRunner function
Return Parameter
List of BLS public keys
getAllDelegetedBLSPublicKeys function
List of all the delegated BLS public keys in the K2 protocol.
Using getAllDelegetedBLSPublicKeys function
Return Parameter
List of BLS public keys