Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
afdaldev opened this issue Mar 15, 2024 · 12 comments
Closed

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

afdaldev opened this issue Mar 15, 2024 · 12 comments

Comments

@afdaldev
Copy link

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
Copy link
Author

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

Screenshot 2024-03-16 at 14 36 55

@quetool
Copy link
Collaborator

quetool commented Mar 19, 2024

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

@afdaldev
Copy link
Author

afdaldev commented Mar 19, 2024

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
Copy link
Author

afdaldev commented Mar 19, 2024

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
Copy link
Collaborator

quetool commented Mar 25, 2024

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

@afdaldev
Copy link
Author

afdaldev commented Mar 27, 2024

@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
Copy link
Collaborator

quetool commented Mar 29, 2024

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

@quetool
Copy link
Collaborator

quetool commented Mar 29, 2024

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
Copy link
Author

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
Copy link
Collaborator

quetool commented Apr 3, 2024

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
Copy link
Author

afdaldev commented Apr 4, 2024

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
Copy link
Collaborator

quetool commented Apr 4, 2024

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

@quetool quetool closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants