import web3
npm install web3
SmartContract ABI
ex: Remix Contract -> ABI
SmartContract Address
ex: Remix Deployes Contract -> Address
const web3Instance = new Web3(Web3.givenProvider || 'http://localhost:7546');
const accounts = await web3Instance.eth.requestAccounts();
SmartContract Connect
CONTACT_ABI, CONTACT_ADDRESS 의 경우 임의의 .js 형태로 import 해서 사용
[config.js]
export const CONTACT_ADDRESS = {contract_address}
export const CONTACT_ABI = {contract_abi}
[app.js]
import { CONTACT_ABI, CONTACT_ADDRESS } from './config';
const contractInstance = new web3Instance.eth.Contract(CONTACT_ABI, CONTACT_ADDRESS);
SmartContract Function Call
Call
transaction 발생하지 않는 함수에 사용(Not gas, Not payable)
myContract.methods.myMethod([param1[, param2[, ...]]]).call(options [, defaultBlock] [, callback])
Send
transaction 이 발생 하는 함수에 사용(gas, payable)
myContract.methods.myMethod([param1[, param2[, ...]]]).send(options[, callback])
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#methods-mymethod-call
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#methods-mymethod-send