目的:尝试从pancakeswap获得价格--我创建了abi,并给它提供了我想要的两个合同地址--但是我得到了这个错误--未处理的异常:类型'_BigIntImpl‘不是'List’类型的子类型
我认为当我调用合同PS时,我在参数中输入错误类型:我也尝试了EthereumAddress作为类型,但是没有工作,您的帮助是非常感谢的。
这是我的代码:
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;
}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
[
{
"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"
},
];发布于 2023-01-23 08:25:40
在ABI文件中,我们有两种类型: uint256 - is BigInt In颤振;address[] -数组EthereumAddresses。
"inputs": [
{
"internalType": "uint256",
"name": "amountIn",
"type": "uint256" <--
},
{
"internalType": "address[]",
"name": "path",
"type": "address[]" <--
}
]因此,在论点中,我们需要这样写:
params: <dynamic>[
BigInt.from(1),
[EthereumAddress.fromHex(tokens[0].address), EthereumAddress.fromHex(tokens[1].address)],
], https://ethereum.stackexchange.com/questions/132987
复制相似问题