Learning Diary, use Web3 to connect Ethereum Smart Contract,学习笔记

in #smartcontract6 years ago (edited)

Screen Shot 2018-05-18 at 12.26.45 PM.png

Hello Steemit friends, so I am trying to do a testing where I try to connect to Ethereum Smart contract using my website and run the function inside the Ethereum Smart contract to show how many fundurian token I have inside a specific ethereum address

  1. create a new html file example test.html

  2. Download a javascript file called web3.min.js from https://github.com/ethereum/web3.js/releases/tag/0.19.0 and put it inside same directory with test.html

  3. On line7, if you have metamask installed you don’t need this line, but if you don’t have metamask installed, you need this line so that web3 can connect to the ethereum node via Infura, you need to get your infura ID from Infura website though

  4. On line 11, you need to paste your contract ABI here, example I used is my own fundurian token contract ABI

  5. On line 12, you put your contract address here, so for my own testing I put my fundurian token contract address

  6. On line 27, you put your ethereum address here, since i have transfer some fundurian token to my new address, i use my new address here

  7. On line 29, here you can call one of the function inside the smart contract, example here is function balanceOf, where it will tell you how much fundurian token you have inside your current address, then it will call the function showResult on line 15

  8. So the showResult function on row15 will update the line34 to show the result of how many fundurian token you have in your ethereum wallet

thanks for reading


大家好,我最近学习如何用网站阅读ethereum的智能合约,比如我创造了fundurian token,我如何从我的地址读取我有多少个fundurian token

1。先创一个html文件叫test.html
2。从https://github.com/ethereum/web3.js/releases/tag/0.19.0下载web3.min.js 然后放到test.html同一个地方
3。第7行,如果你有metamask就不需要,如果你没有metamask,那你就需要这一行去connect到Infura那里,你也需要到Infura网站拿ID先
4。第11行,你需要放入智能合约的ABI,比如我fundurian token的ABI
5。第12行,你需要放你的智能合约的地址,比如我fundurian token的地址
6。第27行,你需要放你ethereum的地址,(比如有fundurian token的ethereum地址)
7。第29行,你可以叫智能合约里的function,比如balanceOf,就可以读取这个ethereum地址有多少个fundurian token,读了后会叫第15行的showResult
8。第15行的showResult会去改第34行告诉你的ethereum地址有多少个fundurian token

谢谢阅读

Sort:  

You've been upvoted by TeamMalaysia Community :-

To support the growth of TeamMalaysia Follow our upvotes by using steemauto.com and follow trail of @myach

Vote TeamMalaysia witness bitrocker2020 using this link vote for witness

你好cn区点赞机器人 @cnbuddy 很开心你能成为cn区的一员。如果不想再收到我的留言,请回复“取消”。

Ropsten is test net hahaha

@therealwolf 's created platform smartsteem scammed my post this morning (mothersday) that was supposed to be for an Abused Childrens Charity. Dude literally stole from abused children that don't have mothers ... on mothersday.

https://steemit.com/steemit/@prometheusrisen/beware-of-smartsteem-scam

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.034
BTC 66274.97
ETH 3175.04
USDT 1.00
SBD 4.06