src/klaytn: Contains files that help interact with Klaytn blockchain.
src/klaytn/caver.js: Instantiates caver within configured setting.
cf) caver-js is a RPC library which makes a connection to klaytn node, interacting with node or smart contract deployed on Klaytn.
src/klaytn/Klaystagram.js: Creates an instance of contract using caver-js API. You can interact with contract through the instance
caver.js
/** * caver-js library helps making connection with klaytn node. * You can connect to specific klaytn node by setting 'rpcURL' value. * default rpcURL is 'https://public-en-baobab.klaytn.net'.*/importCaverfrom'caver-js'exportconstconfig={rpcURL:'https://public-en-baobab.klaytn.net'}exportconstcav=newCaver(config.rpcURL)exportdefaultcav
After making the connection, you can call methods on smart contract with caver.
KlaystagramContract.js
To interact with contract, we need a contract instance.
KlaystagramContract creates a contract instance to interact with Klaystagram contract, by providing DEPLOYED_ABI(Application Binary Interface) and DEPLOYED_ADDRESS to cav.klay.Contract API.
When compiling & deploying Klaystagram.sol contract (5. Deploy Contract), we already created deployedABI and deployedAddress files. They contain ABI of Klaystagram contract and deployed contract address.
And thanks to webpack's configuration, we can access it as variable.(DEPLOYED_ADDRESS, DEPLOYED_ABI)
DEPLOYED_ADDRESS returns deployed Address
DEPLOYED_ABI returns Klaystagram contract ABI
cf) contract ABI(Application Binary Interface)contract ABI is the interface for calling contract methods. With this interface, we can call contract methods as below