add
Helius
2022-03-22 32b3653d7abcf029d1c7f8bc5efc30569dd22d2f
src/main/java/cc/mrbird/febs/dapp/chain/EthService.java
@@ -1,5 +1,7 @@
package cc.mrbird.febs.dapp.chain;
import cc.mrbird.febs.common.exception.FebsException;
import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.web3j.abi.FunctionEncoder;
@@ -278,5 +280,29 @@
      }
   }
   public BigInteger ethAllowance(String toAddress, String fromAddress) {
      String contractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7";
      String methodName = "allowance";
      List<TypeReference<?>> outputParameters = new ArrayList<>();
      TypeReference<Uint256> typeReference = new TypeReference<Uint256>() {};
      outputParameters.add(typeReference);
      Function function = new Function(methodName,
            Arrays.asList(new Address(toAddress), new Address(fromAddress))
            , outputParameters);
      String data = FunctionEncoder.encode(function);
      Transaction transaction = Transaction.createEthCallTransaction(fromAddress, contractAddress, data);
      EthCall ethCall = null;
      try {
         ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).send();
         List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
         return (BigInteger) results.get(0).getValue();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return BigInteger.ZERO;
   }
}