Przeglądaj źródła

首条交易发送成功。

龚成明 3 lat temu
rodzic
commit
3a76da4d48
1 zmienionych plików z 19 dodań i 6 usunięć
  1. 19 6
      test/Univ3Test.ts

+ 19 - 6
test/Univ3Test.ts

@@ -1,6 +1,5 @@
 import { web3 } from "hardhat";
 import deployer from '../.secret'
-const hre = require('hardhat')
 
 describe('Univ3 Test', () => {
   it('Parse ether test', async () => {
@@ -12,11 +11,25 @@ describe('Univ3 Test', () => {
   })
 
   it('Get balance test', async () => {
-    console.log(hre.network)
-    console.log(deployer)
-
-    // console.log(await web3.eth.getBalance(accountList[0]))
+    console.log(await web3.eth.getBalance(deployer.address))
   })
 
-  it('Transfer test')
+  it('Transfer test', async () => {
+    let rawTx = {
+      nonce: await web3.eth.getTransactionCount(deployer.address),
+      gasPrice: web3.utils.toWei('2', 'gwei'),
+      gasLimit: 1_000_000,
+      to: '0x0000000000000000000000000000000000000000',
+      value: '0x05'
+    }
+
+    const signedObj = await web3.eth.accounts.signTransaction(rawTx, deployer.private)
+    if (signedObj.rawTransaction != null) {
+      console.log('ready send hash: ' + signedObj.transactionHash)
+      await web3.eth.sendSignedTransaction(signedObj.rawTransaction).on('error', function (rst) {
+        console.error(rst)
+      })
+      console.log('sent finish.')
+    }
+  })
 })