首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤栗web3dart如何从煎饼中获取价格

颤栗web3dart如何从煎饼中获取价格
EN

Ethereum用户
提问于 2022-08-04 07:49:35
回答 1查看 143关注 0票数 0

目的:尝试从pancakeswap获得价格--我创建了abi,并给它提供了我想要的两个合同地址--但是我得到了这个错误--未处理的异常:类型'_BigIntImpl‘不是'List’类型的子类型

我认为当我调用合同PS时,我在参数中输入错误类型:我也尝试了EthereumAddress作为类型,但是没有工作,您的帮助是非常感谢的。

这是我的代码:

代码语言:javascript
复制
final pancakeSwapContract = '0x10ED43C718714eb63d5aA57B78B54704E256024E';
late Client httpClient;
late Web3Client ethereumClient;
late String _abiCode;
late Credentials _credentials;
String pancakeSwapConAddress = "0x10ED43C718714eb63d5aA57B78B54704E256024E";

String ethereumClientUrl = 'https://bsc-dataseed1.binance.org';
final bnbTokenAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
final tokenAddres = '0xC75aa1Fa199EaC5adaBC832eA4522Cff6dFd521A';
@override
void initState() {
   super.initState();
   httpClient = Client();
   ethereumClient = Web3Client(ethereumClientUrl, httpClient);
}
Future<DeployedContract> getContract() async {
 String abi = await rootBundle.loadString("assets/abi/pancakeSwapAbi.json");
 String pancakeSwapConAddress ="0x10ED43C718714eb63d5aA57B78B54704E256024E".toLowerCase();
 DeployedContract contract = DeployedContract(
 ContractAbi.fromJson(abi, 'pancakeSwapAbi'),
 EthereumAddress.fromHex(pancakeSwapConAddress),
 );
return contract;
}
代码语言:javascript
复制
Future<void> calcBNBPrice() async {
 const bNBTokenAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; //BNB
 const uSDTokenAddress = "0x55d398326f99059fF775485246999027B3197955"; //USDT
 // final EthereumAddress add1 = EthereumAddress.fromHex(bNBTokenAddress);
 // final EthereumAddress add2 = EthereumAddress.fromHex(uSDTokenAddress);
 DeployedContract contract = await getContract();
 getThePriceContract = contract.function("getAmountsOut");
 List<dynamic> gettingThePrice = await ethereumClient.call(
 contract: contract,
 function: getThePriceContract,
 params: [
  BigInt.parse(bNBTokenAddress),
  BigInt.parse(uSDTokenAddress),
 ],
);
final List<dynamic> convertResponse = gettingThePrice.first as List<dynamic>;
print(convertResponse);
}

ABI

代码语言:javascript
复制
[
    {
      "inputs": [
        {"internalType": "uint256", "name": "amountIn", "type": "uint256"},
        {"internalType": "address[]", "name": "path", "type": "address[]"}
      ],
      "name": "getAmountsOut",
      "outputs": [
        {"internalType": "uint256[]", "name": "amounts", "type": "uint256[]"}
      ],
      "stateMutability": "view",
      "type": "function"
    },
  ];
EN

回答 1

Ethereum用户

发布于 2023-01-23 08:25:40

在ABI文件中,我们有两种类型: uint256 - is BigInt In颤振;address[] -数组EthereumAddresses。

代码语言:javascript
复制
   "inputs": [
            {
                "internalType": "uint256",
                "name": "amountIn",
                "type": "uint256" <--
            },
            {
                "internalType": "address[]",
                "name": "path",
                "type": "address[]" <--
            }
        ]

因此,在论点中,我们需要这样写:

代码语言:javascript
复制
params: <dynamic>[
    BigInt.from(1),
    [EthereumAddress.fromHex(tokens[0].address), EthereumAddress.fromHex(tokens[1].address)],
  ], 
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/132987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档