API Specification
console.log(connex.thor.genesis)
>{
"beneficiary": "0x0000000000000000000000000000000000000000",
"gasLimit": 10000000,
"gasUsed": 0,
"id": "0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127",
"number": 0,
"parentID": "0xffffffff00000000000000000000000000000000000000000000000000000000",
"receiptsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",
"signer": "0x0000000000000000000000000000000000000000",
"size": 170,
"stateRoot": "0x4ec3af0acbad1ae467ad569337d2fe8576fe303928d35b8cdd91de47e9ac84bb",
"timestamp": 1530014400,
"totalScore": 0,
"transactions": [],
"txsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"
}
console.log(connex.thor.status)
>{
"head": {
"id": "0x00d801f2b19ece57b722f5a45ee4d0569201e81d40c3efccbf911613be98c05f",
"number": 14156274,
"timestamp": 1671594090,
"parentID": "0x00d801f12541216d63e6e631ab4f2702b11463e649a33120e5a70ff101042e31",
"txsFeatures": 1,
"gasLimit": 30000000
},
"progress": 1,
"finalized": "0x00d7ffdc678fb95d20f9484d9e45966a0db49a2d83222344e005963f3ed76faa"
}
Ticker
is a concept that describes chain increment, when there is a new block added to the chain, ticker will be triggered. This API will create a ticker which has a function that creates a Promise
that will resolve when a new block is truly added, please be advised that it never rejects.Returns
Thor.Ticker
next
- (): Promise<Thor.Status['head']>: Callnext
will create a promise that resolves with the summary of head block when there is a new block added
const ticker = connex.thor.ticker()
ticker.next().then((head)=>{
console.log(head)
})
// After a few seconds
> {
"id": "0x00379f79ce016975dab2aa6ee21669b6ad4f4aa3fbb1ef1dfb151c52e13a8437",
"number": 3645305,
"parentID": "0x00379f781a0035250669e6f5e5170b8cb384decbbb6a83917f823d920de5eed1",
"timestamp": 1566874740,
"txsFeatures": 1,
"gasLimit": 16000000
}
Account visitor is a bunch of APIs to get account details and interact with account methods.
Create an Account Visitor
const acc = connex.thor.account('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed')
Parameters
address
-string
: Account to visit
Returns
AccountVisitor
address
-string(readonly)
: The address of account to be visitedget
-(): Promise<Thor.Account>
: Get the account detailgetCode
-(): Promise<Thor.Account>
: Get the account codegetStorage
-(key: string): Promise<Thor.Account>
: Get the account storagemethod
-(abi: object): Method
: Create a method object, to perform contract call, or build transaction clauseevent
-(abi: object): EventVisitor
: Create an event visitor
Get Account Detail
const acc = connex.thor.account('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed')
acc.get().then(accInfo=>{
console.log(accInfo)
})
>{
"balance": "0xe95ea52e8e07eddd24e",
"energy": "0x920d91d3ff3bb7f1d527",
"hasCode": false
}
Get Account Code
Returns
Promise<Thor.Code>
code
-string
: Contract code of an account
const acc = connex.thor.account('0x0000000000000000000000000000456E65726779')
acc.getCode().then(code=>{
console.log(code)
})
>{
"code": "0x6080604052600436106100af576000357c010000000000000000000000000000000000..."
}
Get Account Storage
Parameters
key
-string
: The key to accessing in account storage
Returns
Promise<Thor.Storage>
value
-string
: The value to the key in account storage
const acc = connex.thor.account('0x0000000000000000000000000000456E65726779')
acc.getStorage('0x0000000000000000000000000000000000000000000000000000000000000001').then(storage=>{
console.log(storage)
})
>{
"value": "0x7107c9b15a7254dd92173d5421359b33bf40ea4ef0fa278ceaf1d320659d5c7b..."
}
Contract Method
Given the ABI of a contract, a
Thor.Method
object can be created to simulate a contract all without altering the contract state as well as pack a method with arguments to a clause that is ready to be signed.const nameABI = {"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"}