-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { ethers } = require('ethers') | ||
const types = require('ethernaut-common/src/validation/types') | ||
const output = require('ethernaut-common/src/ui/output') | ||
const EthernautCliError = require('ethernaut-common/src/error/error') | ||
|
||
require('../scopes/util') | ||
.task('calldata', 'Decodes calldata of a tx') | ||
.addPositionalParam( | ||
'transactionId', | ||
'The transaction to lookup', | ||
undefined, | ||
types.string, | ||
) | ||
.addPositionalParam( | ||
'abi', | ||
'The ABI of the contract to decode the calldata', | ||
undefined, | ||
types.array, | ||
) | ||
.setAction(async ({ transactionId, abi }, hre) => { | ||
try { | ||
const tx = await hre.ethers.provider.getTransaction(transactionId) | ||
|
||
if (!tx) { | ||
throw new EthernautCliError('ethernaut-network', 'No tx found.', false) | ||
} | ||
|
||
const calldata = tx.data | ||
const iface = new ethers.utils.Interface(abi) | ||
const decodedData = iface.parseTransaction({ data: calldata }) | ||
|
||
const callData = { | ||
functionName: decodedData.name, | ||
args: decodedData.args, | ||
} | ||
|
||
return output.resultBox(callData) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |
Oops, something went wrong.