background
The interfaces and transaction types in okexchain is compatible with Ethereum, you can directly use Ethereum client SDK to connect with okexchain, such as ethers.js, truffle, etc.
problem:
Transaction hash mismatch from Provider.sendTransaction.
In the process of using the ethers.js tool to send a transaction to okexchain, an error message that the transaction execution failed appeared, but the transaction was actually successful.
ethers.js error message: Transaction hash mismatch from Provider.sendTransaction.
ethers.js locally generates an Ethereum-style transaction hash h
(rlp encoding + keccak256 hash), and then uses the hash h
to the okexchain chain to check whether the transaction is successful, but the transaction hash h2
on the okexchain (amino code + sha256 hash) is the same as the cosmos style but different from the ethereum style, so the hash h
cannot be found on okexchain. The ethers.js client thinks that the transaction failed, but the transaction was actually sent successfully.
solution:
js
The okexchain team implemented the amino+sha256 algorithm based on the official etherjs, which can generate exchain or cosmos style transaction hashes and project addresses. And named it exchain-ethers and released it to the npm. Developers can install exchain-ethers through the command line to replace the original ethers project.
amino+sha256 ethers.js: https://github.com/okx/ethers.js/releases/tag/v5.4.0.1
sudo npm install exchain-ethers
If you don't plan to use ethers.js, you can also refer to other methods, such as the js version of transaction sending based on truffle.
Code example https://github.com/okx/solidity-sample/blob/main/js/index.js
go
The oec official also provides a way to send transactions to the go version, based on go-ethereum and comos-sdk to achieve transaction sending.
Code example https://github.com/okx/solidity-sample/blob/main/go/exchain-web3-sample/golang/main.go
java
The official oec is also based on web3j, version v3.4.0, which implements the use of java to send transactions.
Code example https://github.com/okx/solidity-sample/blob/main/java/exchain-web3-sample/src/main/java/com/exchain/web3/util/ContractUtilTest.java
Notice:
If the web3j version is higher than v3.4.0, you need to delete the following code in the web3j project:
if (!txHashVerifier.verify(txHashLocal, txHashRemote)) {
throw new TxHashMismatchException(txHashLocal, txHashRemote);
}