Integrating ERC20 Token with the Game Discussion

Dear Moralis,

You seriously need to update the content of this course. I’m sooo frustrated and am about ready to abandon it because I can’t get anything to work, even using Filip’s code with some help provided above by community members (and I’ve spent many hours trying to troubleshoot). Today for some reason I could no longer get the eth.js to integrate with my index file. It was visible in the console yesterday, but not today for some reason.

In essence, I can’t get my index.js and eth.js to actually integrate with my GameToken solidity file.

Anyhow, below is a screenshot of my console where the details of the contract are no longer there (but were there yesterday).

image

1 Like

ive written a guide in each of this coures sections about how to get past some of th emajor pitfalls you should look at it

Hello @CaliCrypto22, good day

Providing some support for you:
In your index.html, try using the following script imports:

...
  <head>

    <meta charset="utf-8">
    <title>Our Awesome Game </title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
    <script src="eth.js"></script>

  </head>
...

If you started a new ‘session’ in Truffle (i.e. say you work on this again the next day) and then execute ‘truffle develop’ that will start a new local emulated blockchain, you then need to deploy your token contract again, double check the localhost socket used if Truffle used localhost:9545. Then, get the token address and modify your eth.js:

var contract = new web3.eth.Contract(abi, "...")

Just a small detail: in your eth.js, add a ‘;’ at line 307 (at the end of the ‘abi’ array).

Hope this is helpful to you.
With kind regards,

Thanks . . . I see your long, helpful post above (April 22) but it sounds like you made another earlier one? In a different section? I can’t seem to find it.

1 Like

hey @CaliCrypto22 if you go to the first fourn in thus course for the smart contract section should be therealso now seems like a good time to teach you git. Ill still clone your code if youcan push propperly. Downloand and isntall git on google once you do use the git add --all etc commands i have shown above to push the code. if you can do it go on youtube and search how to install git and thn google hoe to pudh entire repo to github or something and let me know when you hsve it up

Thanks! I will give it a try.

Okay, thanks . . . I will investigate how to push to git.

Thanks for your help!! . . . I got it working this evening (integration of the index.html, eth.js, and the solidity file (GameToken).

1 Like

hey @CaliCrypto22. ok so i went onto git there and its still not the correct format ill try give you a tutorial now how to push projects up. ok so first thing is to go onto google and download git. just simply google git

click the link highlighted in red. you will be faced with this page


i assume you have windows 10 and a 64 bit computer. if so click the dowloand link i have highlighted and when this downloads open the dowload it will be in you downloads folder and follow the installation process. its just a few button clicks. when you have that done finish and navigate to the root of you prject folder. this is important when i say root i mean you have some folder and inside it is both the backend and frontend code of your project. so go to this folder that has both the backend and front end code. naviagte to this project folder on your computer. i made a dummy folder just to explain my point

right click your mouse on this folder and there will be and option that says “open GIT bash here” choose this option. Once you have done this keep the terminal open and then go to githuub.com. Go to your profile and create a new repository like shown below
git5|690x148

when you do create one give it a name and click create repositry like shpwn below

Once you do you will be faced with these three options in the screengrab below


go back to your terminal and type git init like you can see i am doing. when you do this then use the commands i have shown you in the last post namely

git add --all

then

git commit -m "commit message"

once you have done these then on your repo page copy and paste your version of the commands on the screen shot below. do these one by one thats important

So run these in your terminal then after you run the last one your code will get pushed properly for me to work with

1 Like

Thanks for providing this tutorial. I was able to successfully follow along up to “git add --all” Unfortunately, I encountered the following error after entering the following command: git commit -m “commit message”

Here’s a screenshot of the error I got:

image

just run the commands its telling u to run there

Thanks. It worked! Here’s the link. Feel free to take a look but it’s probably not necessary since everything seems to be working right now.

https://github.com/jsanders108/ETH_GAME

Quick question: If I were to update a backend or frontend file and then push the whole folder again to my github repository I assume everything just gets updated automatically?

~I don’t get it. I was doing the task to create the token, than there was a reading regarding truffle migration and then I started working on this lesson, it ask me to redeploy the contract and then update the eth.js file. When this file was created? I don’t have it.~

~LOL. Suggestions?~

Never mind, read through all the messages and found the missing lesson. I know it’s outdated, but at least I know where to follow now.

1 Like

Hello @williamokano

Good thing you found the missing lesson.

Just to add it here for future reference (making it a more recent post) for others to see and read.

With kind regards,
Alphon

I did not see where and when we setup the eth.js so i copied the one from the completed and trying to get to work for me but get this error below.

web3.min.js:1          POST http://localhost:9545/ net::ERR_CONNECTION_REFUSED
n._onFinish @ web3.min.js:1
(anonymous) @ web3.min.js:1
n.emit @ web3.min.js:1
A @ web3.min.js:1
l @ web3.min.js:1
(anonymous) @ web3.min.js:1
b.run @ web3.min.js:1
p @ web3.min.js:1
setTimeout (async)
u @ web3.min.js:1
o.nextTick @ web3.min.js:1
nextTick @ web3.min.js:1
(anonymous) @ web3.min.js:1
onwrite @ web3.min.js:1
n._write @ web3.min.js:1
_ @ web3.min.js:1
(anonymous) @ web3.min.js:1
f.write @ web3.min.js:1
e._startUpload @ web3.min.js:1
a._sendHxxpRequest @ web3.min.js:1
a._sendHttp @ web3.min.js:1
a.send @ web3.min.js:1
s.send @ web3.min.js:1
u.send @ web3.min.js:1
n @ web3.min.js:1
e @ web3.min.js:1
e @ web3.min.js:1
o._executeMethod @ web3.min.js:1
mintAfterGame @ eth.js:330
updateTimeLeft @ index.html:192
update @ phaser.min.js:1
h.emit @ phaser.min.js:1
step @ phaser.min.js:1
update @ phaser.min.js:1
step @ phaser.min.js:1
step @ phaser.min.js:1
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
web3.min.js:1          POST http://localhost:9545/ net::ERR_CONNECTION_REFUSED
n._onFinish @ web3.min.js:1
(anonymous) @ web3.min.js:1
n.emit @ web3.min.js:1
A @ web3.min.js:1
l @ web3.min.js:1
(anonymous) @ web3.min.js:1
b.run @ web3.min.js:1
p @ web3.min.js:1
setTimeout (async)
u @ web3.min.js:1
o.nextTick @ web3.min.js:1
nextTick @ web3.min.js:1
(anonymous) @ web3.min.js:1
onwrite @ web3.min.js:1
n._write @ web3.min.js:1
_ @ web3.min.js:1
(anonymous) @ web3.min.js:1
f.write @ web3.min.js:1
e._startUpload @ web3.min.js:1
a._sendHxxpRequest @ web3.min.js:1
a._sendHttp @ web3.min.js:1
a.send @ web3.min.js:1
s.send @ web3.min.js:1
u.send @ web3.min.js:1
n @ web3.min.js:1
(anonymous) @ web3.min.js:1
_fireError @ web3.min.js:1
s @ web3.min.js:1
(anonymous) @ web3.min.js:1
i.onreadystatechange @ web3.min.js:1
e.dispatchEvent @ web3.min.js:1
a._setReadyState @ web3.min.js:1
a._onHttpRequestError @ web3.min.js:1
(anonymous) @ web3.min.js:1
n.emit @ web3.min.js:1
(anonymous) @ web3.min.js:1
Promise.then (async)
n._onFinish @ web3.min.js:1
(anonymous) @ web3.min.js:1
n.emit @ web3.min.js:1
A @ web3.min.js:1
l @ web3.min.js:1
(anonymous) @ web3.min.js:1
b.run @ web3.min.js:1
p @ web3.min.js:1
setTimeout (async)
u @ web3.min.js:1
o.nextTick @ web3.min.js:1
nextTick @ web3.min.js:1
(anonymous) @ web3.min.js:1
onwrite @ web3.min.js:1
n._write @ web3.min.js:1
_ @ web3.min.js:1
(anonymous) @ web3.min.js:1
f.write @ web3.min.js:1
e._startUpload @ web3.min.js:1
a._sendHxxpRequest @ web3.min.js:1
a._sendHttp @ web3.min.js:1
a.send @ web3.min.js:1
s.send @ web3.min.js:1
u.send @ web3.min.js:1
n @ web3.min.js:1
e @ web3.min.js:1
e @ web3.min.js:1
o._executeMethod @ web3.min.js:1
mintAfterGame @ eth.js:330
updateTimeLeft @ index.html:192
update @ phaser.min.js:1
h.emit @ phaser.min.js:1
step @ phaser.min.js:1
update @ phaser.min.js:1
step @ phaser.min.js:1
step @ phaser.min.js:1
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
requestAnimationFrame (async)
e @ phaser.min.js:1
web3.min.js:1 Uncaught (in promise) Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (web3.min.js:1:347694)
    at a.i.onreadystatechange (web3.min.js:1:763941)
    at a.e.dispatchEvent (web3.min.js:1:750746)
    at a._setReadyState (web3.min.js:1:756980)
    at a._onHttpRequestError (web3.min.js:1:760643)
    at s.exports.<anonymous> (web3.min.js:1:758145)
    at s.exports.n.emit (web3.min.js:1:175893)
    at web3.min.js:1:280840```
1 Like

Hello @Scott815

See the previous post for your reference, in finding the ‘lost’ lesson.

With kind

the web3.min.js file will now work. its too old. you need to use a cdn. put this above your jas imports in index.html

<script 
        src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.6.1/web3.min.js" 
        integrity="sha512-5erpERW8MxcHDF7Xea9eBQPiRtxbse70pFcaHJuOhdEBQeAxGQjUwgJbuBDWve+xP/u5IoJbKjyJk50qCnMD7A==" 
        crossorigin="anonymous" 
        referrerpolicy="no-referrer">
</script>
1 Like

I cannot seem to be able to connect my token to the game. When I load up my game on the local host it gives 2 errors.

1 Like

can u share a picture or the code of you script import for connection.js in your html file

When I ran Truffle Develop on the solidity folder it gave me this statement “Truffle Develop started at http://127.0.0.1:9545/

Therefore when coding the first line I inputted that address.
web3 = new Web3(new Web3.providers.HttpProvider(“http://127.0.0.1:9545”));

Now when I try to connect on a terminal with localhost, I get this error below.