Interacting with smartcontracts

hi, I am new to this platform and trying to learn new technologies as the part of the hackathon.

i have been trying to connect to an existing eth contract and execute functions on that contract but I am receiving 403 error.

const provider = new ethers.providers.JsonRpcProvider({
url: ‘https://goerli.ethereum.coinbasecloud.net’,
user: ‘user’,
password: ‘password’,
});
const signer =await provider.getSigner();
const contract =await new ethers.Contract(masteraddress, masterABI, signer);
const statusUser=await contract.createAccount(id,name)

can anyone help me out!

Hello @shivaraj! Welcome to the forum!

Thank you for providing information regarding the error code you’ve experienced. 403 error code is usually due to the request being forbidden and you may have hit your rate limit. You may check this documentation to know more. Additionally, some error code is caused due to misconfiguration or something malformed on the query/request sent.

We also noted that you’re utilizing the Goerli Testnet and so we advise reviewing the Ethereum API Docs and the documentation provided on how to execute eth smart contracts: Ethereum API Overview. If you’re still experiencing an error after reviewing the above, please let us know and we will be happy to investigate this further.

Thank you and again welcome to the community!

5 Likes

hi @Bazinga,
I am not able to understand how to interact with a smart contract.
if possible can you share a basic piece of code interacting with a smart contract functions.

Hello @shivaraj! Thank you for updating us with your concern.

Related to this, please allow us to clarify some things first so we could better assist you with your inquiry.

  1. Can you share with us your intended use case for this matter?
  2. Are you having trouble with integrating the smart contract with your project or are you encountering issues on having your code work with the smart contract?
  3. Can you specify further where you are getting stuck? It would also be better if you could share with us the full scenario of the steps you took and the blockage you are having, so we could investigate further.

In the meantime, we also recommend you to refer to this Coinbase Cloud article for a simplified tutorial of how to write a smart contract and how to use the Node product from Coinbase Cloud to deploy the smart contract on Ethereum’s Goerli network. You may also refer to this website Ethereum.org as they have an array of resources which may be of help.

Once you send us the information requested above, we’ll work to quickly address your concern. We appreciate your patience and understanding.

1 Like

I am building an DApp for the hackathon conducted by coinbase and hackerearth.
I have built few DApp’s in the ethereum before. SO, I have a some knowledge on writing the smart contracts and integrating with UI.

accessing the smart contract without the node provider works totally fine and I works perfect. but when I try to connect through the coinbase node provider , the request fails and returns a 403 error.
I didnt cross the rate limit so, I believe that is not the issue.
probably what I think is by looking at the docs, probably I believe the code which I wrote with ether.js must be wrong.

Following code works fine:-

let provider = new ethers.providers.Web3Provider(window.ethereum.providers.find((x) => x.isCoinbaseWallet));
const signer =await provider.getSigner();
const contract =await new ethers.Contract(masteraddress, masterABI, signer);
const res=await contract.createAccount(UID,UNAME);

but if I replace the provider with coinbase node as follows, it dosn’t work.

const provider = new ethers.providers.JsonRpcProvider({
url: ‘https://goerli.ethereum.coinbasecloud.net’,
user: ‘<-----userID----->’,
password: ‘<-----password------>’,
});
const signer =await provider.getSigner();
const contract =await new ethers.Contract(masteraddress, masterABI, signer);
const res=await contract.createAccount(UID,UNAME);

This is the error which I get while I try to run the above piece of code.

I beleive I am trying to contact to the contract with the node as provider in a wrong manner. but at the same time I cant find the correct way of doing it as well.

It would be great if someone can help me out on this issue :slightly_smiling_face: .

Hi @shivaraj, thank you so much for your patience! With regards to the issue you’re encountering, it seems that the web server understands the request but cannot provide the access (forbidden). What you can do is to create environment variables, store the credentials in the environment variables and then invoke them later in the program. For instructions on how to do it, please refer to this page from our documentation: Ethers.js

Hope this helps!

1 Like

I am quiet confident that thats not the problem, but I’ll give it a try for now.
edited:- “it dosent fix the issue”