![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
find-replacement-tx
Advanced tools
Ethereum wallets have the functionality to speed up
or cancel
transactions. This has the effect of replacing a not yet mined transaction with another transaction of same nonce and different hash.
Dapp interfaces need a way to check for these replacement transactions.
This tool searches for replacement transactions of same nonce within a safe reorg height (binary searched).
findReplacementTx
Transaction
is returned if findReplacementTx
found a transaction with expected parameters (nonce, from, to, data, value, event)findReplacementTx
will throw a TxValidationError
if the transaction couldn't be validated: canceled, different destination, different data (optional) or event not validated(optional).findReplacementTx
will throw a SearchError
if no transaction could be found within the search range.null
is returned if the transaction is not yet mined.getTransactionByNonce
Transaction
with the same nonce is returned.getTransactionByNonce
will throw a SearchError
if no transaction could be found within the search range.null
is returned if the transaction is not yet mined.Related work: https://eips.ethereum.org/EIPS/eip-2831
yarn add find-replacement-tx
"dependencies": {
"find-replacement-tx": "^1.0.0",
}
Find and validate a replacement transaction (Metamask speedup).
import { findReplacementTx } from 'find-replacement-tx'
const erc20Contract = new web3.eth.Contract(
erc20Abi,
erc20TokenAddress,
{ from }
)
// If this tx is dropped and replaced, lower the search boundary
// in case there was a reorg.
const safeReorgHeight = await web3.eth.getBlockNumber() - 20
const approvalHash = await new Promise((resolve, reject) => {
erc20Contract.methods
.approve(spender, amount).send()
.on('transactionHash', resolve)
.catch(reject)
})
const pendingApprovalTx = await web3.eth.getTransaction(approvalHash)
// `tx` and `event` are necessary to validate how the transaction was replaced:
// speed up: same nonce, valid event emitted
// cancel: same nonce, different `tx.to`
const tx = {
nonce: pendingApprovalTx.nonce,
from: pendingApprovalTx.from,
to: pendingApprovalTx.to,
data: pendingApprovalTx.data, // (optional)
value: pendingApprovalTx.value // (optional)
}
// Validating an event is optional as tx.data should be sufficient in most cases.
const event = { // (optional)
name: 'Approval',
abi: erc20Abi,
address: erc20TokenAddress,
validate: ({ returnValues: { owner, spender, value } }) => {
return (
owner.toLowerCase() === transfer.sender.toLowerCase() &&
spender.toLowerCase() === process.env.ethLockerAddress.toLowerCase()
// Don't check value as the user may have increased approval before signing.
// value === transfer.amount
)
}
}
try {
const foundTx = await findReplacementTx(provider, transfer.ethCache.safeReorgHeight, tx, event)
if (!foundTx) {
// Tx pending
}
const approvalReceipt = await web3.eth.getTransactionReceipt(foundTx.hash)
} catch (error) {
if (error instanceof SearchError) {
// No transaction found with given nonce inside the seach range
} else if (error instanceof TxValidationError) {
// Transactions canceled or replaced by unknown transaction
} else {
// Other errors like a networking error.
}
}
Query a transaction by nonce.
Similar to web3.eth.getTransaction
.
Returns a Transaction
object or null
if transaction nonce is pending. Throws if transaction is not found within range.
import { getTransactionByNonce } from 'find-replacement-tx'
const startSearch = await web3.eth.getBlockNumber() - 20
const transaction = await getTransactionByNonce(
provider, // Web3 provider
startSearch, // Lower search bound
from, // Transaction signer
nonce // Nonce of transaction to get
)
FAQs
Unknown package
We found that find-replacement-tx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.