|
@@ -7,6 +7,11 @@ import {ethers} from "ethers";
|
|
|
import web3 from "web3";
|
|
import web3 from "web3";
|
|
|
let tokenpocketBnb = {}
|
|
let tokenpocketBnb = {}
|
|
|
|
|
|
|
|
|
|
+let contractArr=[
|
|
|
|
|
+ '0x15ef4d92595aad506885861668cf463c09d1063e',//token
|
|
|
|
|
+ '0x337610d27c682e347c9cd60bd4b3b107c9d34ddd',//usdt
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
let chainId=''
|
|
let chainId=''
|
|
|
let provider;
|
|
let provider;
|
|
@@ -40,6 +45,7 @@ tokenpocketBnb.getProvider= function (){
|
|
|
chainId=ethChainId
|
|
chainId=ethChainId
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
return provider;
|
|
return provider;
|
|
|
}
|
|
}
|
|
@@ -106,6 +112,45 @@ tokenpocketBnb.getBalance=async function (selectedAddress) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 获取合约数量
|
|
|
|
|
+ * @param selectedAddress
|
|
|
|
|
+ * @param contractType
|
|
|
|
|
+ * @returns {Promise<number>}
|
|
|
|
|
+ */
|
|
|
|
|
+tokenpocketBnb.getTokenBalance=async function (selectedAddress,contractType) {
|
|
|
|
|
+ if(!contractType){
|
|
|
|
|
+ contractType=0
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!selectedAddress){
|
|
|
|
|
+ selectedAddress=tokenpocketBnb.getMyAddress();
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(selectedAddress)
|
|
|
|
|
+ let data='0x70a08231000000000000000000000000'+(selectedAddress.substring(2))
|
|
|
|
|
+ console.log(web3.utils.isHex(`0x70a08231`))
|
|
|
|
|
+ console.log(data)
|
|
|
|
|
+ return new Promise( (resolve, reject) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ let data='0x70a08231000000000000000000000000'+(selectedAddress.substring(2))
|
|
|
|
|
+ console.log([{'to':contractArr[contractType],'data':data}, "latest"],data)
|
|
|
|
|
+ tokenpocketBnb.getProvider().request({method: 'eth_call',params:[{'to':contractArr[contractType],'data':data}, "latest"]}).then((balance)=>{
|
|
|
|
|
+ console.log("balanceNum:",web3.utils.hexToNumber(balance))
|
|
|
|
|
+ balance= (web3.utils.hexToNumber(balance)/(contractType===1?1000000:1000000000000000000)).toString()
|
|
|
|
|
+ if(balance<0.000001){
|
|
|
|
|
+ balance=0
|
|
|
|
|
+ }
|
|
|
|
|
+ resolve(balance)
|
|
|
|
|
+ }).catch((e)=>{
|
|
|
|
|
+ console.log(e)
|
|
|
|
|
+ resolve(0)
|
|
|
|
|
+ })
|
|
|
|
|
+ }catch (e) {
|
|
|
|
|
+ // alert('error:'+JSON.stringify(e))
|
|
|
|
|
+ reject(e)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取gasPrice
|
|
* 获取gasPrice
|
|
@@ -149,8 +194,8 @@ tokenpocketBnb.getTransactionData=async function (to,money){
|
|
|
data.to=to;
|
|
data.to=to;
|
|
|
data.from=tokenpocketBnb.getMyAddress();
|
|
data.from=tokenpocketBnb.getMyAddress();
|
|
|
data.gasPrice=await tokenpocketBnb.getGasPrice();
|
|
data.gasPrice=await tokenpocketBnb.getGasPrice();
|
|
|
- data.gas=await tokenpocketBnb.getEstimateGas();
|
|
|
|
|
data.chainId=chainId;
|
|
data.chainId=chainId;
|
|
|
|
|
+ data.gas=await tokenpocketBnb.getEstimateGas(data);
|
|
|
if(tools.isDevelopment()){
|
|
if(tools.isDevelopment()){
|
|
|
money=0.00001;
|
|
money=0.00001;
|
|
|
}
|
|
}
|