Developers Forum for XinFin XDC Network

Luv Malani
Luv Malani

Posted on • Updated on

Issues with Contract Verification and Interaction on Metamask

Interaction with my contract

Hello everyone,

I'm facing a couple of issues with my smart contract deployment and interaction process and would appreciate any guidance you could offer. I am trying on testnet.

  1. Contract Verification Issue: When trying to verify my contract using Solidity (Multi-file), I'm encountering the following error: Cannot POST /smart-contracts/0x5454f0766b879fcd0497f77a6d46276e9e47ec9e/verification/via/multi-part. I've followed the typical steps for multi-file verification but can't seem to get past this error.

  2. Interaction Issue with Metamask: When attempting to interact with my contract using my application, I've tried using the contract address in both formats: "xdc........" and "0x........". Unfortunately, neither of them seem to work, and I'm unable to transact through Metamask.

    The error messages indicate invalid Ethereum addresses and mention that the network doesn't support EIP-1559. I've double-checked the addresses and am sure they are correct. Here's a snippet of the error message for context (not verbatim):

- Invalid address error for "0xdc........"
- Invalid value error for EIP-1559, indicating network incompatibility
Enter fullscreen mode Exit fullscreen mode

Has anyone faced similar issues or have any insights on how to resolve these problems? Any advice on the next steps would be greatly appreciated.

Thank you!

Discussion (12)

Collapse
gzliudan profile image
Daniel Liu

What's address of your RPC server ?

Collapse
luv_malani_dae959d40aee9c profile image
Luv Malani Author

We're using metamask on our frontend code, and it is working on other chains.

this is the code, which works fine for all other chains like arbitrum and eth:
if (window.ethereum) {
try {
const web3 = new Web3(window.ethereum);
await window.ethereum.request({ method: "eth_requestAccounts" }); // Request account access
const accounts = await web3.eth.getAccounts();
const fromAddress = accounts[0];

    const jobDetails = {
      title: jobTitle,
      description: jobDescription,
      type: jobType,
      jobTaker: jobTaker,
      amount: amount,
      jobGiver: fromAddress,
    };

    // Pin job details to IPFS
    const response = await pinJobDetailsToIPFS(jobDetails);

    if (response && response.IpfsHash) {
      const jobDetailHash = response.IpfsHash;
      console.log("IPFS Hash:", jobDetailHash);

      const contract = new web3.eth.Contract(
        JobContractABI,
        contractAddress,
      );

      // Convert amount to Wei
      const amountInWei = web3.utils.toWei(amount, "ether");

      // Send transaction
      await contract.methods
        .enterDirectContract(jobDetailHash, jobTaker)
        .send({
          from: fromAddress,
          value: amountInWei,
        });

      console.log("Transaction successful");
    } else {
      console.error("Failed to pin job details to IPFS");
    }
  } catch (error) {
    console.error("Error sending transaction:", error);
  }
} else {
  console.error("MetaMask not detected");
}
Enter fullscreen mode Exit fullscreen mode

};

const pinJobDetailsToIPFS = async (jobDetails) => {
const url = api.pinata.cloud/pinning/pinJSONTo...;
const headers = {
"Content-Type": "application/json",
pinata_api_key: pinataApiKey,
pinata_secret_api_key: pinataSecretApiKey,
};

const body = JSON.stringify({
  pinataOptions: { cidVersion: 1 },
  pinataMetadata: { name: "JobDetails.json" },
  pinataContent: jobDetails,
});

try {
  const response = await fetch(url, {
    method: "POST",
    headers: headers,
    body: body,
  });

  const data = await response.json();
  return data;
} catch (error) {
  console.error("Error pinning to IPFS:", error);
  return null;
}
Enter fullscreen mode Exit fullscreen mode

};

Collapse
luv_malani_dae959d40aee9c profile image
Luv Malani Author • Edited on

We're using metamask on our frontend code, and it is working on other chains. Other chains do not require us to,

Do you have sample frontend code to call a writefunction on xdc, that would help?

Collapse
logeswaran profile image
Lokesh

Try this NPM package -> npmjs.com/package/react-solidity-xdc3

Which has a boilerplate for you to kick-start the dapp development on XDC. Also note that, you may have to change the RPC URl's that's mentioned below

Thread Thread
anasshaikh profile image
AnasShaikh

Hi Lokesh, I'm from the same team who posted this thread. I tried this package and still doesn't work, this package has too many warnings and is too complex to use compared to achieving similar functionality with other chains. Do you have react or JS code which is working currently or has worked in the recent past? Or any other approach I should try and yes I did try the different RPCs

Collapse
logeswaran profile image
Lokesh
Thread Thread
luv_malani_dae959d40aee9c profile image
Luv Malani Author

tried but error not resolved and the 2nd link is not even working

Thread Thread
anasshaikh profile image
AnasShaikh

Hi team, any update on my query above??

Hi Lokesh, I'm from the same team who posted this thread. I tried this package and still doesn't work, this package has too many warnings and is too complex to use compared to achieving similar functionality with other chains. Do you have react or JS code which is working currently or has worked in the recent past? Or any other approach I should try and yes I did try the different RPCs

Thread Thread
logeswaran profile image
Lokesh

Interesting!, that package has been helpful for quite number of dapps. Neverthless, we will address your feedback, thanks for raising that.

Meanwhile, have you tried XDCPay chrome extension to transact with your contract. If not, can you try that out and share your feedback here?

List of active RPC's, you can get it from chainlist.org/?search=xdc

Also, pls note the address "- Invalid address error for "0xdc........" occurs when you use the RPC's which doesn't support 0x conversion.

How to validate?-
RPC address prefixed with "e" should be the right one to convert the address from xdc to 0x. For example -- erpc.apothem.network for testnet

and erpc.xinfin.network for mainnet.

Try this out and let us know your feedback..

Thread Thread
anasshaikh profile image
AnasShaikh

Thanks for the reply Lokesh. Was curious if you can consult for like an hour, I think it should be more than enough to solve my problem. Let me know what you would charge. This will save my time too.

Thread Thread
anasshaikh profile image
AnasShaikh

Thanks so much for your help guys, I figured it. I had to just modify the transaction to use the legacy transaction format instead of EIP-1559

Collapse
ani_gray_f06511247189a464 profile image
ANI gray

one has to be guiDed a lot of sc.mmers are out there taking money from innocent traders. I was a victim to this sc.m crypto broker the made me loss my hard earn funds.
I rep0rted to Jeffsilbert 3 9 g ma!l c0m and He was able to fight back for my funds now I have my fvnds fully rec0 vered.