Developers Forum for XinFin XDC Network

Discussion on: Issues with Contract Verification and Interaction on Metamask

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
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
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