Calling Ethereum contract
It is possible to perform a cross-chain call and access a contract that is deployed on Ethereum from within an Orbs contract.
The API for this is included in the ethereum library:
The library exposes several different functions described on this page.
GetBlockNumber
This function is used to get the latest 'safe' block number in Ethereum. The 'safe' block means a block which is in the past, around 25 minutes, to avoid forks.
GetBlockNumberByTime
This function is used to get the block number which was mined just after the timestamp, as long as it is also 'safe'. Safe is defined internally by the SDK as a block which is in the past, around 25 minutes, to avoid forks.
The argument GetBlockNumberByTime
takes is:
ethBlockTimestamp
- The Ethereum timestamp in Unix epoch nanoseconds to search for corresponding block.
GetBlockTime
This function is used to get the block timestamp (Unix epoch in nanoseconds) of the latest 'safe' block number in Ethereum. The 'safe' block means a block which is in the past, around 25 minutes, to avoid forks.
GetBlockTimeByNumber
This function is used to get the block timestamp (Unix epoch in nanoseconds) of the requested block number, as long as it is also 'safe'. Safe is defined internally by the SDK as a block which is in the past, around 25 minutes, to avoid forks.
The argument GetBlockTimeByNumber
takes is:
ethBlockNumber
- The Ethereum block number to get the block's timestamp.
CallMethod
This function is used to perform a method call on ethereum, the action performed in this function is call
in ethereum - we do not perform transactions from within our blockchain, mainly due to response time and finality considerations.
The arguments CallMethod
takes are:
contractAddress
- The Ethereum contract address with a 0x prefixjsonAbi
- The ABI of the call, as a JSON stringmethodName
- The method to call in the contractout
- The result of the contract call - this needs to be a pointer to the expected return value/struct, the struct members need to be defined as PascalCase style, see examples belowargs
- The variadic parameter list for the method you are calling on Ethereum
For example, using the following contract on Ethereum:
If we want to call getValues
we use the following code in our Orbs contract:
CallMethodAtBlock
This function is the same as the CallMethod function, and it only allows to define which block you want to use.
GetTransactionLog
This function can enable you to access the Transaction Receipt of a specific transaction on Ethereum to access and filter its logs according to a specific event name.
The arguments GetTransactionLog
takes are:
ethContractAddress
- The Ethereum contract address with a 0x prefixjsonAbi
- The ABI of the contract with the event, as a JSON stringethTxHash
- The Ethereum transaction address with a 0x prefixeventName
- The event to filter byout
- The event data, this needs to be a pointer to the expected return value/struct, the struct members need to be defined as PascalCase style. See an example below.
The function returns:
ethBlockNumber
- The block number of the log requestedethTxIndex
- The transaction index in the block
An example of using the GetTransactionLog()
for the following event ABI:
The Orbs contract code should look like:
Last updated