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
- currentProvider
- givenProvider
- getBlockRef
- getBlockUncleCount
- getChainTag
- getEnergy
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:
meterify.eth.getAccounts(console.log);
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe" ,"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d"]
meterify.eth.getProtocolVersion([callback])
Returns the protocol version of the node.
Example:
meterify.eth.getProtocolVersion().then(console.log);
> "63"
Returns:
Type | Description |
Promise<string> | The protocol version. |
meterify.eth.isSyncing([callback])
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:
meterify.eth.isSyncing()
.then(console.log);
​
> {
startingBlock: 100,
currentBlock: 312,
highestBlock: 512,
knownStates: 234566,
pulledStates: 123455
}
meterify.eth.getCoinbase([callback])
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:
meterify.eth.getCoinbase().then(console.log);
> "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe"
meterify.eth.isMining([callback])
Checks whether the node is mining or not.
Returns:
Type | Description |
Promise<boolean> | Returns true if the node is mining, otherwise false . |
Example:
meterify.eth.isMining().then(console.log);
> true
meterify.eth.getHashrate([callback])
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:
meterify.eth.getHashrate().then(console.log);
> 493736
meterify.eth.getGasPrice([callback])
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. |
Example:
meterify.eth.getGasPrice().then(console.log);
> "20000000000"
meterify.eth.getAccounts([callback])
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:
meterify.eth.getAccounts().then(console.log);
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
meterify.eth.getBlockNumber([callback])
Returns the current block number.
Returns:
Type | Description |
Promise<number> | The number of the most recent block. |
Example:
meterify.eth.getBlockNumber().then(console.log);
> 2744
meterify.eth.getBalance(address [, defaultBlock] [, callback])
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 | (optional) If you pass this parameter it will not use the default block set with meterify.eth.defaultBlock . |
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 . |
Example:
meterify.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
> "1000000000000"
meterify.eth.getEnergy(address [, defaultBlock] [, callback])
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 | (optional) If you pass this parameter it will not use the default block set with meterify.eth.defaultBlock . |
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> . |
Example:
meterify.eth.getEnergy("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
> "1000000000000"
meterify.eth.getStorageAt(address, position [, defaultBlock] [, callback])
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 | (optional) If you pass this parameter it will not use the default block set with meterify.eth.defaultBlock . |
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:
meterify.eth.getStorageAt("0x407d73d8a49eeb85d32cf465507dd71d507100c1", 0).then(console.log);
> "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"
meterify.eth.getCode(address [, defaultBlock] [, callback])
Get the code at a specific address.
Parameters:
Property | Type | Description |
address | String | The address to get the code from. |
defaultBlock | Number or String | (optional) If you pass this parameter it will not use the default block set with meterify.eth.defaultBlock . |
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:
meterify.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8").then(console.log);
> "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
meterify.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])
Returns a block matching the block number or block hash.
Parameters:
Property | Type | Description |
blockHashOrBlockNumber | String or Number | The block number or block hash. Or the string "genesis" , "latest" or "pending" as in the default block parameter . |
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:
meterify.eth.getBlock(3150).then(console.log);
> {
"number": 3,
"hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
"parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88",
"nonce": "0xfb6e1a62d119228b",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"transactionsRoot": "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee",
"stateRoot": "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb",
"receiptsRoot": '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
"miner": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty": '21345678965432',
"totalDifficulty": '324567845321',
"size": 616,
"extraData": "0x",
"gasLimit": 3141592,
"gasUsed": 21662,
"timestamp": 1429287689,
"transactions": [
"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b"
],
"uncles": []
}
meterify.eth.getBlockTransactionCount(blockHashOrBlockNumber [, callback])
Returns the number of transaction in a given block.
Parameters:
Property | Type | Description |
blockHashOrBlockNumber | String or Number | The block number or hash. Or the string "genesis" , "latest" or "pending" as in the default block parameter . |
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:
meterify.eth.getBlockTransactionCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
> 1
meterify.eth.getUncle(blockHashOrBlockNumber, uncleIndex [, callback])
Returns a blocks uncle by a given uncle index position.
Parameters:
Property | Type | Description |
blockHashOrBlockNumber | String or Number | The block number or hash. Or the string "genesis" , "latest" or "pending" as in the default block parameter . |
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:
meterify.eth.getUncle(500, 0).then(console.log);
> // see meterify.eth.getBlock
meterify.eth.getTransaction(transactionHash [, callback])
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:
meterify.eth.getTransaction('0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b§234').then(console.log);
> {
"hash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"nonce": 2,
"blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
"blockNumber": 3,
"transactionIndex": 0,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"value": '123450000000000000',
"gas": 314159,
"gasPrice": '2000000000000',
"input": "0x57cb2fc4"
}
meterify.eth.getPendingTransactions([, callback])
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:
meterify.eth.getPendingTransactions().then(console.log);
> [
{
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
nonce: 2,
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
blockNumber: 3,
transactionIndex: 0,
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
value: '123450000000000000',
gas: 314159,
gasPrice: '2000000000000',
input: '0x57cb2fc4'
v: '0x3d',
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
},....,{
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
nonce: 3,
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
blockNumber: 4,
transactionIndex: 0,
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
value: '123450000000000000',
gas: 314159,
gasPrice: '2000000000000',
input: '0x57cb2fc4'
v: '0x3d',
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
}
]
getTransactionFromBlock(hashStringOrNumber, indexNumber [, callback])
Returns a transaction based on a block hash or number and the transactions index position.
Parameters: