Meter Docs
Search…
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:
1
meterify.eth.getAccounts(console.log);
Copied!
1
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe" ,"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d"]
Copied!

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

1
meterify.eth.getProtocolVersion([callback])
Copied!
Returns the protocol version of the node.
Example:
1
meterify.eth.getProtocolVersion().then(console.log);
2
> "63"
Copied!
Returns:
Type
Description
Promise<string>
The protocol version.

isSyncing

1
meterify.eth.isSyncing([callback])
Copied!
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:
1
meterify.eth.isSyncing()
2
.then(console.log);
3
4
> {
5
startingBlock: 100,
6
currentBlock: 312,
7
highestBlock: 512,
8
knownStates: 234566,
9
pulledStates: 123455
10
}
Copied!

getCoinbase

1
meterify.eth.getCoinbase([callback])
Copied!
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:
1
meterify.eth.getCoinbase().then(console.log);
2
> "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe"
Copied!

isMining

1
meterify.eth.isMining([callback])
Copied!
Checks whether the node is mining or not.
Returns:
Type
Description
Promise<boolean>
Returns true if the node is mining, otherwise false.
Example:
1
meterify.eth.isMining().then(console.log);
2
> true
Copied!

getHashrate

1
meterify.eth.getHashrate([callback])
Copied!
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:
1
meterify.eth.getHashrate().then(console.log);
2
> 493736
Copied!

getGasPrice

1
meterify.eth.getGasPrice([callback])
Copied!
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:
1
meterify.eth.getGasPrice().then(console.log);
2
> "20000000000"
Copied!

getAccounts

1
meterify.eth.getAccounts([callback])
Copied!
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:
1
meterify.eth.getAccounts().then(console.log);
2
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
Copied!

getBlockNumber

1
meterify.eth.getBlockNumber([callback])
Copied!
Returns the current block number.
Returns:
Type
Description
Promise<number>
The number of the most recent block.
Example:
1
meterify.eth.getBlockNumber().then(console.log);
2
> 2744
Copied!

getBalance

1
meterify.eth.getBalance(address [, defaultBlock] [, callback])
Copied!
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:
1
meterify.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
2
> "1000000000000"
Copied!

getEnergy

1
meterify.eth.getEnergy(address [, defaultBlock] [, callback])
Copied!
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:
1
meterify.eth.getEnergy("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
2
> "1000000000000"
Copied!

getStorageAt

1
meterify.eth.getStorageAt(address, position [, defaultBlock] [, callback])
Copied!
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:
1
meterify.eth.getStorageAt("0x407d73d8a49eeb85d32cf465507dd71d507100c1", 0).then(console.log);
2
> "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"
Copied!

getCode

1
meterify.eth.getCode(address [, defaultBlock] [, callback])
Copied!
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:
1
meterify.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8").then(console.log);
2
> "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
Copied!

getBlock

1
meterify.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])
Copied!
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:
1
meterify.eth.getBlock(3150).then(console.log);
2
> {
3
"number": 3,
4
"hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
5
"parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88",
6
"nonce": "0xfb6e1a62d119228b",
7
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
8
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
9
"transactionsRoot": "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee",
10
"stateRoot": "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb",
11
"receiptsRoot": '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
12
"miner": "0x8888f1f195afa192cfee860698584c030f4c9db1",
13
"difficulty": '21345678965432',
14
"totalDifficulty": '324567845321',
15
"size": 616,
16
"extraData": "0x",
17
"gasLimit": 3141592,
18
"gasUsed": 21662,
19
"timestamp": 1429287689,
20
"transactions": [
21
"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b"
22
],
23
"uncles": []
24
}
Copied!

getBlockTransactionCount

1
meterify.eth.getBlockTransactionCount(blockHashOrBlockNumber [, callback])
Copied!
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:
1
meterify.eth.getBlockTransactionCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
2
> 1
Copied!

getUncle

1
meterify.eth.getUncle(blockHashOrBlockNumber, uncleIndex [, callback])
Copied!
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>
The returned uncle. For a return value see meterify.eth.getBlock().
Note: An uncle doesn't contain individual transactions.
Example:
1
meterify.eth.getUncle(500, 0).then(console.log);
2
> // see meterify.eth.getBlock
Copied!

getTransaction

1
meterify.eth.getTransaction(transactionHash [, callback])
Copied!
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:
1
meterify.eth.getTransaction('0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b§234').then(console.log);
2
> {
3
"hash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
4
"nonce": 2,
5
"blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
6
"blockNumber": 3,
7
"transactionIndex": 0,
8
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
9
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
10
"value": '123450000000000000',
11
"gas": 314159,
12
"gasPrice": '2000000000000',
13
"input": "0x57cb2fc4"
14
}
Copied!

getPendingTransactions

1
meterify.eth.getPendingTransactions([, callback])
Copied!
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:
1
meterify.eth.getPendingTransactions().then(console.log);
2
> [
3
{
4
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
5
nonce: 2,
6
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
7
blockNumber: 3,
8
transactionIndex: 0,
9
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
10
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
11
value: '123450000000000000',
12
gas: 314159,
13
gasPrice: '2000000000000',
14
input: '0x57cb2fc4'
15
v: '0x3d',
16
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
17
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
18
},....,{
19
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
20
nonce: 3,
21
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
22
blockNumber: 4,
23
transactionIndex: 0,
24
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
25
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
26
value: '123450000000000000',
27
gas: 314159,
28
gasPrice: '2000000000000',
29
input: '0x57cb2fc4'
30
v: '0x3d',
31
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
32
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
33
}
34
]
Copied!

getTransactionFromBlock

1
getTransactionFromBlock(hashStringOrNumber, indexNumber [, callback])
Copied!
Returns a transaction based on a block hash or number and the transactions index position.
Parameters:
Property
Type
Description
hashStringOrNumber
String
A block number or hash. Or the string "genesis", "latest" or "pending" as in the default block parameter.
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>
A transaction object, seemeterify.eth.getTransaction
Example:
1
const transaction = meterify.eth.getTransactionFromBlock('0x4534534534', 2).then(console.log);
2
> // see meterify.eth.getTransaction
Copied!

getTransactionReceipt

1
meterify.eth.getTransactionReceipt(hash [, callback])
Copied!
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:
1
const receipt = meterify.eth.getTransactionReceipt('0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b')
2
.then(console.log);
3
> {
4
"status": true,
5
"transactionHash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
6
"transactionIndex": 0,
7
"blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
8
"blockNumber": 3,
9
"contractAddress": "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe",
10
"cumulativeGasUsed": 314159,
11
"gasUsed": 30234,
12
"logs": [{
13
// logs as returned by getPastLogs, etc.
14
}, ...]
15
}
Copied!

getTransactionCount

1
meterify.eth.getTransactionCount(address [, defaultBlock] [, callback])
Copied!
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
(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<number>
The number of transactions sent from the given address.
Example:
1
meterify.eth.getTransactionCount("0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe").then(console.log);
2
> 1
Copied!

sendTransaction

1
meterify.eth.sendTransaction(transactionObject [, callback])
Copied!
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
The address for the sending account. Uses the meterify.eth.defaultAccount property, if not specified. Or an address or index of a local wallet in meterify.eth.accounts.wallet.
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
(optional) The price of gas for this transaction in wei, defaults to meterify.eth.gasPrice.
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
A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:
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
Is fired for every confirmation up to the 12th confirmation. Receives the confirmation number as the first and the receipt as the second argument. Fired from confirmation 0 on, which is the block where it's mined.
"error"
Error
Is fired if an error occurs during sending. If a out of gas error, the second parameter is the receipt.
Example:
1
// compiled solidity source code using https://remix.ethereum.org
2
const code = "603d80600c6000396000f3007c01000000000000000000000000000000000000000000000000000000006000350463c6888fa18114602d57005b6007600435028060005260206000f3";
3
4
// using the callback
5
meterify.eth.sendTransaction({
6
from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
7
data: code // deploying a contract
8
}, function(error, hash){
9
...
10
});
11
12
// using the promise
13
meterify.eth.sendTransaction({
14
from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
15
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
16
value: '1000000000000000'
17
})
18
.then(function(receipt){
19
...
20
});
21
22
// using the event emitter
23
meterify.eth.sendTransaction({
24