WalletConnect / Web3ModalFlutter

The Web3Modal for WalletConnect built using Flutter.
https://pub.dev/packages/web3modal_flutter
Apache License 2.0
27 stars 30 forks source link

How I can get multiple value from requestReadContract function? #99

Closed afdaldev closed 1 month ago

afdaldev commented 2 months ago

Describe the bug I try to read smart contract with requestReadContract,, for single value response is good.. but, for multiple value i just get response 1 value

Expected behavior my expectation return list of value => [maxCap,lockedPeriod,apy ,rewardPercent,totalStaked] My ABI: "name": "pools", "outputs": [ {"internalType": "uint256", "name": "maxCap", "type": "uint256"}, {"internalType": "uint256", "name": "lockedPeriod", "type": "uint256"}, {"internalType": "uint256", "name": "apy", "type": "uint256"}, {"internalType": "uint256", "name": "rewardPercent", "type": "uint256"}, {"internalType": "uint256", "name": "totalStaked", "type": "uint256"} ],

Actual behavior I just get single response => result: 10000000000000000000000000 (value of maxCap)

afdaldev commented 2 months ago

this issue coming from WalletConnectFlutterV2 ,, just return result.first

Screenshot 2024-03-16 at 14 36 55

quetool commented 2 months ago

Hello, @afdaldev ! Could you post a reproducible pice of code so I can check?

afdaldev commented 2 months ago
final deployedContract = DeployedContract(
              ContractAbi.fromJson(
                abiCode,
                'ISOMAStaking',
              ),
              EthereumAddress.fromHex(
                '0x89E0633eA38CD3539A69A9f88F410A3133f61cF1',
              ),
            );

            final result = await walletConnect.w3mService.requestReadContract(
              deployedContract: deployedContract,
              functionName: 'pools',
              rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545',
              parameters: [
                BigInt.from(0),
              ],
            );

            log.d('$result');

here @quetool ..

and now i using web3dart to ReadContract. because, the return data is List<dynamic>

may you can change return of requestReadContract and requestWriteContract to List<dynamic> like from web3dart

afdaldev commented 2 months ago
ABI ``` [ { "inputs": [ { "internalType": "address", "name": "_token", "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [ ], "name": "AmountExceedStakedAmount", "type": "error" }, { "inputs": [ ], "name": "AmountShouldBeGreaterThanZero", "type": "error" }, { "inputs": [ ], "name": "ApyRangeExceeds", "type": "error" }, { "inputs": [ ], "name": "CanNotClaimMainToken", "type": "error" }, { "inputs": [ ], "name": "EnterValidAmount", "type": "error" }, { "inputs": [ ], "name": "ExceedPoolCap", "type": "error" }, { "inputs": [ ], "name": "InvalidMaxCapPerWallet", "type": "error" }, { "inputs": [ ], "name": "InvalidMaxPoolLimit", "type": "error" }, { "inputs": [ ], "name": "InvalidPool", "type": "error" }, { "inputs": [ ], "name": "LockupPeriodNotPassed", "type": "error" }, { "inputs": [ ], "name": "MaxFeeCap", "type": "error" }, { "inputs": [ ], "name": "NothingStaked", "type": "error" }, { "inputs": [ ], "name": "PercentShouldBeAtleastFive", "type": "error" }, { "inputs": [ ], "name": "WalletCapExceeds", "type": "error" }, { "inputs": [ ], "name": "ZeroAddress", "type": "error" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "Deposit", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "EmergencyWithdraw", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "OwnershipTransferStarted", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "RewardClaimed", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "Withdraw", "type": "event" }, { "inputs": [ ], "name": "DIVISOR", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ ], "name": "acceptOwnership", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_poolId", "type": "uint256" }, { "internalType": "address", "name": "_user", "type": "address" } ], "name": "calculateRewards", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "otherToken", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "claimOtherERC20Tokens", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_poolId", "type": "uint256" } ], "name": "claimReward", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_poolId", "type": "uint256" }, { "internalType": "uint256", "name": "_amountToStake", "type": "uint256" } ], "name": "deposit", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ ], "name": "depositFeePercentage", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "ejectReward", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "poolId", "type": "uint256" } ], "name": "emergencyWithdraw", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ ], "name": "feeWallet", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "tokenAmount", "type": "uint256" } ], "name": "injectReward", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ ], "name": "owner", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ ], "name": "penaltyPercentage", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ ], "name": "pendingOwner", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "name": "poolRewards", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "name": "pools", "outputs": [ { "internalType": "uint256", "name": "maxCap", "type": "uint256" }, { "internalType": "uint256", "name": "lockedPeriod", "type": "uint256" }, { "internalType": "uint256", "name": "apy", "type": "uint256" }, { "internalType": "uint256", "name": "rewardPercent", "type": "uint256" }, { "internalType": "uint256", "name": "totalStaked", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ ], "name": "renounceOwnership", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ ], "name": "token", "outputs": [ { "internalType": "contract IERC20", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ ], "name": "totalRewards", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "transferOwnership", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "newDepositFee", "type": "uint256" }, { "internalType": "uint256", "name": "newWithdrawlFee", "type": "uint256" } ], "name": "updateDepositAndWithdrawFee", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "newFeeWallet", "type": "address" } ], "name": "updateFeeWallet", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "internalType": "uint256", "name": "newCap", "type": "uint256" } ], "name": "updateMaxCapPerWalletForPool", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "newPenaltyFee", "type": "uint256" } ], "name": "updatePenaltyFee", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_poolId", "type": "uint256" }, { "internalType": "uint256", "name": "_newAPY", "type": "uint256" } ], "name": "updatePoolAPY", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "internalType": "uint256", "name": "newLimit", "type": "uint256" } ], "name": "updatePoolMaxLimit", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_poolId", "type": "uint256" }, { "internalType": "uint256", "name": "newPercentage", "type": "uint256" } ], "name": "updateRewardAllocationPercentage", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "address", "name": "", "type": "address" } ], "name": "users", "outputs": [ { "internalType": "uint256", "name": "stakedAmount", "type": "uint256" }, { "internalType": "uint256", "name": "lastDepositTime", "type": "uint256" }, { "internalType": "uint256", "name": "lastRewardClaim", "type": "uint256" }, { "internalType": "uint256", "name": "rewardClaimed", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "name": "walletCap", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "poolId", "type": "uint256" }, { "internalType": "uint256", "name": "_amountToWithdraw", "type": "uint256" } ], "name": "withdraw", "outputs": [ ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ ], "name": "withdrawalFeePercentage", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" } ] ```
quetool commented 1 month ago

@afdaldev what should be the expected result? Could you provide a working example? using web3dart maybe?

afdaldev commented 1 month ago

@quetool here : Web3Example

i think you just need to change return of requestReadContract to List<dynamic> and return value from Web3dart Because, i see Here you return result.first

quetool commented 1 month ago

Hello @afdaldev I'll check this ASAP or you can also open a PR for this and I'll review it

quetool commented 1 month ago

Hello @afdaldev! I just pushed a fix, could you check by using

dependencies:
  walletconnect_flutter_v2: ^2.2.2-beta02

If you instead need this fix on web3modal_flutter then for now you can just add this new dependency overrides options as follows:

dependencies:
  web3modal_flutter: ^3.1.2

dependency_overrides:
  walletconnect_flutter_v2: ^2.2.2-beta02
afdaldev commented 1 month ago

i have try in : https://github.com/afdaldev/Web3Dart_Example/tree/testing_read_contract_with_web3modal

thanks @quetool it's working like my expectation. i will wait for next release version in web3modal_flutter

quetool commented 1 month ago

Hello @afdaldev! Are you ok with the current solution? if you don't get the proper response type you can try w3mService.web3App!.requestWriteContract()

afdaldev commented 1 month ago

sure, this is good solution for me. because, i can get all information from my smart contract

for w3mService.web3App!.requestWriteContract(). i don't get any problem.. i still use this function to write

quetool commented 1 month ago

Sounds good! I'll close this issue for now and I'll let you know then the fix is on web3modal as well. Thanks!