meterify.eth
This module allows you to interact with a Meter blockchain and any deployed smart contracts on it.
Although the meterify.eth
module inherits from web.eth
, there are some feature differences between the two. The following is a list of extended features in meterify.eth
Extended Properties
currentProvider
givenProvider
Extended Methods
getBlockRef
getBlockUncleCount
getChainTag
getEnergy
Note on checksum addresses
All addresses returned by functions of this package are returned as checksum addresses. This means some letters are uppercase and some are lowercase. Based on that it will calculate a checksum for the address and prove its correctness. Incorrect checksum addresses will throw an error when passed into functions. If you want to circumvent the checksum check you can make an address all lower- or uppercase.
Checksum Example:
Contract
For meterify.eth.Contract
see the Contract
reference documentation.
accounts
For meterify.eth.accounts
see the accounts
reference documentation.
options
For meterify.eth.options
see the options
reference documentation.
getProtocolVersion
Returns the protocol version of the node.
Example:
Returns:
Type
Description
Promise<string>
The protocol version.
isSyncing
Checks if the node is currently syncing and returns either a syncing object, or false
.
Returns:
Type
Description
Promise <objectboolean>
Property
Type
Description
startingBlock
Number
The block number where the sync started.
currentBlock
Number
The block number where at which block the node currently synced to already.
highestBlock
Number
The estimated block number to sync to.
knownStates
Number
The estimated states to download
pulledStates
Number
The already downloaded states
Example:
getCoinbase
Returns the Coinbase address to which mining rewards will go.
Returns:
Type
Description
Promise<string>
The Coinbase address set in the node for mining rewards.
Example:
isMining
Checks whether the node is mining or not.
Returns:
Type
Description
Promise<boolean>
Returns true
if the node is mining, otherwise false
.
Example:
getHashrate
Returns the number of hashes per second that the node is mining with.
Returns:
Type
Description
Promise<number>
The number of hashes per second.
Example:
getGasPrice
Returns the current gas price oracle. The gas price is determined by the last few blocks median gas price. GasPrice is the wei per unit of gas.
Returns:
Type
Description
Promise<string>
Number string of the current gas price in wei.
See the A note on dealing with big numbers in JavaScript.
Example:
getAccounts
Will return a list of the unlocked accounts in the Web3 wallet or it will return the accounts from the currently connected node.
This means you can add accounts with meterify.eth.accounts.create()
and you will get them returned here.
Returns:
Type
Description
Promise<Array>
An array of addresses controlled by node.
Example:
getBlockNumber
Returns the current block number.
Returns:
Type
Description
Promise<number>
The number of the most recent block.
Example:
getBalance
Get the Meter MTRG balance of an address at a given block.
Property
Type
Description
address
String
The address to get the balance of.
defaultBlock
Number
or String
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<string>
The current Meter balance for the given address in wei
.
See the `A note on dealing with big numbers in JavaScript'.
Example:
getEnergy
Get the Meter MTR (energy) balance of an address at a given block.
Property
Type
Description
address
String
The address to get the balance of.
defaultBlock
Number
or String
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<string>
The current Meter MTR balance for the given address in wei <what-is-wei>
.
See the A note on dealing with big numbers in JavaScript.
Example:
getStorageAt
Get the storage at a specific position of an address.
Parameters:
Property
Type
Description
address
String
The address to get the storage from.
position
Number
The index position of the storage.
defaultBlock
Number
or String
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<string>
The value in storage at the given position.
Example:
getCode
Get the code at a specific address.
Parameters:
Property
Type
Description
address
String
The address to get the code from.
defaultBlock
Number
or String
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<string>
The data at given address address
.
Example:
getBlock
Returns a block matching the block number or block hash.
Parameters:
Property
Type
Description
blockHashOrBlockNumber
String
or Number
returnTransactionObjects
Boolean
(optional, default false
) If true
, the returned block will contain all transactions as objects, if false
it will only contains the transaction hashes.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<object>
The block object.
The block object:
Property
Type
Description
number
Number
The block number. null
when its pending block.
hash
32 Bytes
String
Hash of the block. null
when its pending block.
parentHash
32 Bytes
String
Hash of the parent block.
nonce
8 Bytes
String
Hash of the generated proof-of-work. null
when its pending block.
sha3Uncles
32 Bytes
String
SHA3 of the uncles data in the block.
logsBloom
256 Bytes
String
The bloom filter for the logs of the block. null
when its pending block.
transactionsRoot
32 Bytes
String
The root of the transaction trie of the block
stateRoot
32 Bytes
String
The root of the final state trie of the block.
receiptsRoot
32 Bytes
String
Transaction receipts are used to store the state after a transaction has been executed and are kept in an index-keyed trie. The hash of its root is placed in the block header as the receipts root.
miner
String
The address of the beneficiary to whom the mining rewards were given.
difficulty
String
Integer of the difficulty for this block.
totalDifficulty
String
Integer of the total difficulty of the chain until this block.
extraData
String
The "extra data" field of this block.
size
Number
Integer the size of this block in bytes.
gasLimit
Number
The maximum gas allowed in this block.
gasUsed
Number
The total used gas by all transactions in this block.
timestamp
Number
or String
The unix timestamp for when the block was collated (returns a string if a overflow got detected).
transactions
Array
Array of transaction objects, or 32 Bytes transaction hashes depending on the returnTransactionObjects
parameter.
uncles
Array
Array of uncle hashes.
Example:
getBlockTransactionCount
Returns the number of transaction in a given block.
Parameters:
Property
Type
Description
blockHashOrBlockNumber
String
or Number
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<number>
The number of transactions in the given block.
Example:
getUncle
Returns a blocks uncle by a given uncle index position.
Parameters:
Property
Type
Description
blockHashOrBlockNumber
String
or Number
uncleIndex
Number
The index position of the uncle.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<object>
Note: An uncle doesn't contain individual transactions.
Example:
getTransaction
Returns a transaction matching the given transaction hash.
Parameters:
Property
Type
Description
transactionHash
String
The transaction hash.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<object>
A transaction object its hash transactionHash
:
The object:
Property
Type
Description
hash
32 Bytes
String
Hash of the transaction.
nonce
Number
The number of transactions made by the sender prior to this one.
blockHash
32 Bytes
String
Hash of the block where this transaction was in. null
when its pending.
blockNumber
Number
Block number where this transaction was in. null
when its pending.
transactionIndex
Number
Integer of the transactions index position in the block. null
when its pending.
from
String
Address of the sender.
to
String
Address of the receiver. null
when its a contract creation transaction.
value
String
Value transferred in wei
.
gasPrice
String
The wei per unit of gas provided by the sender in wei
.
gas
Number
Gas provided by the sender.
input
String
The data sent along with the transaction.
Example:
getPendingTransactions
Returns a list of pending transactions.
Parameters:
Property
Type
Description
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<object[]>
Array of pending transactions:
The object:
Property
Type
Description
hash
32 Bytes
String
Hash of the transaction.
nonce
Number
The number of transactions made by the sender prior to this one.
blockHash
32 Bytes
String
Hash of the block where this transaction was in. null
when its pending.
blockNumber
Number
Block number where this transaction was in. null
when its pending.
transactionIndex
Number
Integer of the transactions index position in the block. null
when its pending.
from
String
Address of the sender.
to
String
Address of the receiver. null
when its a contract creation transaction.
value
String
Value transferred in wei
.
gasPrice
String
The wei per unit of gas provided by the sender in wei
.
gas
Number
Gas provided by the sender.
input
String
The data sent along with the transaction.
Example:
getTransactionFromBlock
Returns a transaction based on a block hash or number and the transactions index position.
Parameters:
Property
Type
Description
hashStringOrNumber
String
indexNumber
Number
The transactions index position.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<object>
Example:
getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
Note: The receipt is not available for pending transactions and returns null
.
Parameters:
Property
Type
Description
hash
String
The transaction hash.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise
returns Object
A transaction receipt object, or null
when no receipt was found:
The object:
Property
Type
Description
status
Boolean
TRUE
if the transaction was successful, FALSE
, if the EVM reverted the transaction.
blockHash
32 Bytes
String
Hash of the block where this transaction was in.
blockNumber
Number
Block number where this transaction was in.
transactionHash
32 Bytes
String
Hash of the transaction.
transactionIndex
Number
Integer of the transactions index position in the block.
from
String
Address of the sender.
to
String
Address of the receiver. null
when its a contract creation transaction.
contractAddress
String
The contract address created, if the transaction was a contract creation, otherwise null
.
cumulativeGasUsed
Number
The total amount of gas used when this transaction was executed in the block.
gasUsed
Number
The amount of gas used by this specific transaction alone.
logs
Array
Array of log objects, which this transaction generated.
Example:
getTransactionCount
Get the numbers of transactions sent from this address.
Parameters:
Property
Type
Description
address
String
The address to get the numbers of transactions from.
defaultBlock
Number
or String
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<number>
The number of transactions sent from the given address.
Example:
sendTransaction
Sends a transaction to the network.
Parameters:
Property
Type
Description
transactionObject
Object
The transaction object to send.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
The transactionObject
Property
Type
Description
from
String
or Number
to
String
(optional) The destination address of the message, left undefined for a contract-creation transaction.
value
Number
, String
, BN
, or BigNumber
(optional) The value transferred for the transaction in wei
, also the endowment if it's a contract-creation transaction.
gas
Number
(optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).
gasPrice
Number
, String
, BN
, or BigNumber
data
String
(optional) Either a ABI byte string <http://solidity.readthedocs.io/en/latest/abi-spec.html>
_ containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialization code.
nonce
Number
(optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
Note: The from
property can also be an address or index from the meterify.eth.accounts.wallet
. It will then sign locally using the private key of that account, and send the transaction via meterify.eth.sendSignedTransaction()
.
Returns:
The callback will return the 32 bytes transaction hash.
Name
Description
PromiEvent
Event
Returns
Description
"transactionHash"
String
Is fired right after the transaction is sent and a transaction hash is available.
"receipt"
Object
Is fired when the transaction receipt is available.
"confirmation"
Number
, Object
"error"
Error
Is fired if an error occurs during sending. If a out of gas error, the second parameter is the receipt.
Example:
sendSignedTransaction
Sends an already signed transaction, generated for example using meterify.eth.accounts.signTransaction
.
Parameters:
Property
Type
Description
signedTransactionData
String
Signed transaction data in HEX format
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Name
Returns
Description
PromiEvent
Please see the return values for meterify.eth.sendTransaction
for details.
Example:
sign
Signs data using a specific account. This account needs to be unlocked.
Parameters:
Property
Type
Description
dataToSign
String
address
String
or Number
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Note: The 2. address
parameter can also be an address or index from the meterify.eth.accounts.wallet
. It will then sign locally using the private key of this account.
Returns:
Type
Description
Promise<string>
The signature.
Example:
signTransaction
Signs a transaction with the private key of the given address. If the given address is a local unlocked account, the transaction will be signed locally.
Parameters:
Property
Type
Description
transactionObject
Object
address
string
The address of the account.
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<object>
Example:
call
Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.
Parameters:
Property
Type
Description
callObject
Object
defaultBlock
Number
or String
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<string>
The returned data of the call, e.g. a smart contract functions return value.
Example:
estimateGas
Executes a message call or transaction and returns the amount of the gas used.
Parameters:
Property
Type
Description
callObject
Object
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<number>
The used gas for the simulated call/transaction.
Example:
getPastLogs
Gets past logs, matching the given options.
Parameters:
Property
Type
Description
options
Object
The filter options as follows:
callback
Function
(optional) Optional callback,
The options
object:
Property
Type
Description
fromBlock
Number
or String
The number of the earliest block ("latest"
may be given to mean the most recent and "pending"
currently mining, block). By default "latest"
.
toBlock
Number
or String
The number of the latest block ("latest"
may be given to mean the most recent and "pending"
currently mining, block). By default "latest"
.
address
String
or Array
An address or a list of addresses to only get logs from particular account(s).
topics
Array
An array of values which must each appear in the log entries. The order is important, if you want to leave topics out use null
, e.g. [null, '0x12...']
. You can also pass an array for each topic with options for that topic e.g. [null, ['option1', 'option2']]
Returns:
Type
Description
Promise<Array>
Array of log objects.
The structure of the returned event Object
in the Array
looks as follows:
Name
Type
Description
address
String
From which this event originated from.
data
String
The data containing non-indexed log parameter.
topics
Array
An array with max 4 32 Byte topics, topic 1-3 contains indexed parameters of the log.
logIndex
Number
Integer of the event index position in the block.
transactionIndex
Number
Integer of the transaction's index position, the event was created in.
transactionHash
32 Bytes
String
Hash of the transaction this event was created in.
blockHash
32 Bytes
String
Hash of the block where this event was created in. null
when its still pending.
blockNumber
Number
The block number where this log was created in. null
when still pending.
Example:
getWork
Gets work for miners to mine on. Returns the hash of the current block, the seedHash, and the boundary condition to be met ("target").
Parameters:
Property
Type
Description
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<Array>
The mining work with the following structure:
Type
Description
String
32 Bytes - at index 0
current block header pow-hash
String
32 Bytes - at index 1
the seed hash used for the DAG.
String
32 Bytes - at index 2
the boundary condition ("target"), 2^256 / difficulty.
Example:
submitWork
Used for submitting a proof-of-work solution.
Parameters:
Property
Type
Description
nonce
String
8 Bytes
The nonce found (64 bits)
powHash
String
32 Bytes
The header's pow-hash (256 bits)
digest
String
32 Bytes
The mix digest (256 bits)
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<boolean>
Returns true
if the provided solution is valid, otherwise false.
Example:
requestAccounts
This method will request/enable the accounts from the current environment it is running (Metamask, Status or Mist). It doesn't work if you're connected to a node with a default Web3.js provider (WebsocketProvider, HttpProvidder and IpcProvider). This method will only work if you're using the injected provider from an application like Status, Mist or Metamask.
For further information about the behavior of this method please read the EIP of it: EIP-1102
Parameters:
Property
Type
Description
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<Array>
Returns an array of enabled accounts.
Example:
getChainId
Returns the chain ID of the current connected node as described in EIP-695
.
Returns:
Type
Description
Promise<Number>
Returns chain ID.
Example:
getNodeInfo
Returns:
Type
Description
Promise<String>
The current client version.
Example:
getProof
Returns the account and storage-values of the specified account including the Merkle-proof as described in EIP-1186
.
Parameters:
Property
Type
Description
address
String
20 Bytes
The Address of the account or contract.
storageKey
Array
32 Bytes
blockNumber
Number
or String
or "latest"
or "earliest"
Integer block number, or the string "latest" or "earliest".
callback
Function
(optional) Optional callback, returns an error object as first parameter and the result as second.
Returns:
Type
Description
Promise<Object>
A account object.
The account object:
Property
Description
balance
codeHash
Hash of the code of the account. For a simple Account without code it will return "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
nonce
Nonce of the account.
storageHash
SHA3 of the StorageRoot. All storage will deliver a MerkleProof starting with this rootHash.
accountProof
Array of rlp-serialized MerkleTree-Nodes, starting with the stateRoot-Node, following the path of the SHA3 (address) as key.
storageProof
Array of storage-entries as requested.
key
The requested storage key.
value
The storage value.
Example:
Last updated