Bladeren bron

simple transaction

龚成明 3 jaren geleden
bovenliggende
commit
dccac72f8a
2 gewijzigde bestanden met toevoegingen van 19 en 8 verwijderingen
  1. 0 0
      abi/WETH_ABI.ts
  2. 19 8
      test/BaseOperationTest.ts

File diff suppressed because it is too large
+ 0 - 0
abi/WETH_ABI.ts


+ 19 - 8
test/BaseOperationTest.ts

@@ -16,20 +16,31 @@ describe('Base operation test', () => {
 
   it('Transfer test', async () => {
     let rawTx = {
+      from: deployer.address,
       nonce: await web3.eth.getTransactionCount(deployer.address),
       gasPrice: web3.utils.toWei('2', 'gwei'),
       gasLimit: 1_000_000,
       to: '0x0000000000000000000000000000000000000000',
-      value: '0x10'
+      value: 1e9
     }
 
-    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.')
+    await web3.eth.sendTransaction(rawTx).then(console.log)
+  })
+
+  it('Weth  test', async () => {
+    const WETH_ABI = require('../abi/WETH_ABI').default
+    const WETH_ADDR = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
+
+    let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
+    // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
+
+    let rawTx = {
+      from: deployer.address,
+      nonce: await web3.eth.getTransactionCount(deployer.address),
+      gasPrice: web3.utils.toWei('2', 'gwei'),
+      gasLimit: 1_000_000,
+      to: '0x0000000000000000000000000000000000000000'
     }
+    await weth_contract.methods.withdraw(1e9).send(rawTx).then(console.log)
   })
 })

Some files were not shown because too many files changed in this diff