Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cmp20test
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
explorer-for-cmp20
cmp20test
Commits
5efbb9ab
Commit
5efbb9ab
authored
Dec 15, 2025
by
Developer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test script
parent
b40aa685
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
gascost.js
scripts/gascost.js
+58
-0
No files found.
scripts/gascost.js
0 → 100644
View file @
5efbb9ab
const
{
ContractFactory
}
=
require
(
"
ethers
"
);
const
hre
=
require
(
"
hardhat
"
);
async
function
forceRevert
()
{
// 部署合约
const
factory
=
await
hre
.
ethers
.
getContractFactory
(
"
RevertContract
"
);
const
contract
=
await
factory
.
deploy
();
await
contract
.
waitForDeployment
();
const
contractAddress
=
await
contract
.
getAddress
();
console
.
log
(
"
Contract deployed at:
"
,
contractAddress
);
const
signer
=
new
hre
.
ethers
.
Wallet
(
process
.
env
.
DEPLOY_PRIVATE_KEY
,
hre
.
ethers
.
provider
);
const
transferAmount
=
hre
.
ethers
.
parseEther
(
"
1
"
);
// 小于 1 ETH
var
nonce
=
await
hre
.
ethers
.
provider
.
getTransactionCount
(
signer
.
address
)
const
chainid
=
await
hre
.
ethers
.
provider
.
getNetwork
().
then
(
network
=>
network
.
chainId
);
// Encode the function call
const
abi
=
[
"
function sendViaTransfer(address payable _to, uint256 _amount)
"
];
const
iface
=
new
hre
.
ethers
.
Interface
(
abi
);
const
data
=
iface
.
encodeFunctionData
(
"
sendViaTransfer
"
,
[
'
0xAD4143Df8Fe9E31B1C4318e8dE555872085f481d
'
,
transferAmount
]);
var
balance
=
await
hre
.
ethers
.
provider
.
getBalance
(
signer
.
address
);
console
.
log
(
"
Sender balance:
"
,
hre
.
ethers
.
formatEther
(
balance
),
"
ETH
"
);
// 签名交易
const
signedTx
=
await
signer
.
signTransaction
({
type
:
0
,
chainId
:
chainid
,
nonce
:
nonce
,
to
:
contractAddress
,
data
:
data
,
value
:
transferAmount
,
gasLimit
:
1000000
,
// 设置 gas 限制
gasPrice
:
hre
.
ethers
.
parseUnits
(
"
10000
"
,
"
gwei
"
),
// 设置 gas 价格
});
// 发送交易
const
txResponse
=
await
hre
.
ethers
.
provider
.
broadcastTransaction
(
signedTx
);
console
.
log
(
"
Transaction sent:
"
,
txResponse
.
hash
);
// wait receipt
const
receipt
=
await
txResponse
.
wait
();
console
.
log
(
"
Transaction receipt:
"
,
receipt
);
balance
=
await
hre
.
ethers
.
provider
.
getBalance
(
signer
.
address
);
console
.
log
(
"
Sender balance:
"
,
hre
.
ethers
.
formatEther
(
balance
),
"
ETH
"
);
}
// Define the script
async
function
main
()
{
await
forceRevert
()
}
// Run the script
main
().
catch
((
error
)
=>
{
console
.
error
(
"
Error:
"
,
error
);
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment