web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

Interacting with contract method not working

Open RajKumar7777 opened this issue 4 years ago • 5 comments

Hi,

When I try to interact with contract it does not working.

    let formattedKey = PrivateKey.trimmingCharacters(in: .whitespacesAndNewlines)
    let dataKey = Data.fromHex(formattedKey)!
    let keystore = try! EthereumKeystoreV3(privateKey: dataKey, password: "")!
    let keystoreManager = KeystoreManager([keystore])
    web3.addKeystoreManager(keystoreManager)
    
    guard let contract = web3.contract(abiString, at: EthereumAddress("0xc6E070BCb7823E483164bB41D2297DCd8b1FAb25"), abiVersion: 2) else {
        return
    }

   print("contract methods", contract.method())

   It does not comes to print the contract methods..it stops working by return.
  
    My contract ABI: https://api-testnet.bscscan.com/api?module=contract&action=getabi&address=0xc6E070BCb7823E483164bB41D2297DCd8b1FAb25&apikey=

  Please help to find the solution

RajKumar7777 avatar Aug 18 '21 08:08 RajKumar7777

Hello.

In order to make debug process easier: Please specify full code with Networks.Custom(networkID: BigUInt(networkID) initialisation.

As I can see you are interacting with the BSC chain. I didn't test it. And BSC is out of my scope of interests. So I would be happy t merge PR with this fix.

skywinder avatar Aug 20 '21 01:08 skywinder

Hi @skywinder ,

RpcUrl: https://data-seed-prebsc-1-s1.binance.org:8545/
Chain ID: Networks.Custom(networkID: 0x61)

I can able to connect with BSC. I can able to send bsc and bep20 tokens.
But cant able interact with dynamic contract method.

Please support with any solution..

Thanks

RajKumar7777 avatar Aug 20 '21 04:08 RajKumar7777

Yeah Its likely chain ID. You need to set it before the tx if you are using a private chain.

transaction?.transaction.UNSAFE_setChainID(Ennvironment.ethNetworkID)

dangell7 avatar Sep 02 '21 22:09 dangell7

Are you still having trouble with this?

dangell7 avatar Sep 17 '21 16:09 dangell7

@dangell7 yes..I cant interact with BEP20 tokens.

RajKumar7777 avatar Sep 18 '21 06:09 RajKumar7777