{ val amountOut =map["amountOut"] as Int val address =Gson().fromJson(map["address"] as JsonArray,object :TypeToken>(){}.ty_web3j swapexacttokensf">
当前位置:   article > 正文

UniSwap 使用Web3j 生成原生币兑换代币。_web3j swapexacttokensforeth

web3j swapexacttokensforeth
val function =when(methodName){
        "swapEthForExactTokens" -> {
            val amountOut =map["amountOut"] as Int
            val address =Gson().fromJson<String>(map["address"] as JsonArray,object :TypeToken<List<String>>(){}.type).map { Address(it.toString()) }
            val toAddress =map["to"] as String
            val deadline =map["deadline"] as Int
            Function(  methodName, listOf(Uint(amountOut.toBigInteger()), DynamicArray(address), Address(toAddress), Uint(deadline.toBigInteger())),listOf(object : TypeReference<Type<*>?>() {}))
        }
        else ->Function(methodName, listOf(Address(approveToAddress), Uint256(num.toPlainString().toBigInteger())), listOf(object : TypeReference<Type<*>?>() {}))
    }

    //创建RawTransaction交易对象
    val rawTransaction = RawTransaction.createTransaction(nonce.toBigInteger(), gasPrice.toBigInteger(), gasLimit.toBigInteger(), contractAddress,  FunctionEncoder.encode(function))

    //签名Transaction
    val signMessage = TransactionEncoder.signMessage(rawTransaction,  Credentials.create(fromPrivateKey))
    return Numeric.toHexString(signMessage)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/900092
推荐阅读