From 15a3c94abc774643284c3d595a2655eb9347dccb Mon Sep 17 00:00:00 2001 From: Tschakki Date: Thu, 22 Feb 2024 14:35:18 +0100 Subject: [PATCH] Deploy website - based on 9402b207c41def9a766fc8d2c689f7ac1742a4e8 --- 404.html | 2 +- add-token-to-lisk.html | 2 +- assets/js/0c54d7a4.a9badad3.js | 1 - assets/js/0c54d7a4.b2e63e7e.js | 1 + ...ain.b1737035.js => runtime~main.1657047f.js} | 2 +- .../deploying-a-smart-contract.html | 2 +- building-on-lisk/ethers.html | 17 +++++++++++------ building-on-lisk/migration-guide.html | 2 +- category/building-on-lisk.html | 2 +- connecting-to-a-wallet.html | 2 +- contracts.html | 2 +- fees.html | 2 +- index.html | 2 +- lisk-tools/api-providers.html | 2 +- lisk-tools/bridges.html | 2 +- markdown-page.html | 2 +- network-info.html | 2 +- 17 files changed, 26 insertions(+), 21 deletions(-) delete mode 100644 assets/js/0c54d7a4.a9badad3.js create mode 100644 assets/js/0c54d7a4.b2e63e7e.js rename assets/js/{runtime~main.b1737035.js => runtime~main.1657047f.js} (98%) diff --git a/404.html b/404.html index e7d120e6f..6d64dd2fa 100644 --- a/404.html +++ b/404.html @@ -4,7 +4,7 @@ Lisk Documentation - + diff --git a/add-token-to-lisk.html b/add-token-to-lisk.html index b34923527..e463076e4 100644 --- a/add-token-to-lisk.html +++ b/add-token-to-lisk.html @@ -4,7 +4,7 @@ Adding an ERC-20 Token to Lisk | Lisk Documentation - + diff --git a/assets/js/0c54d7a4.a9badad3.js b/assets/js/0c54d7a4.a9badad3.js deleted file mode 100644 index f717673b1..000000000 --- a/assets/js/0c54d7a4.a9badad3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunklisk_docs=self.webpackChunklisk_docs||[]).push([[422],{6680:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>s,contentTitle:()=>r,default:()=>h,frontMatter:()=>c,metadata:()=>o,toc:()=>l});var i=n(5893),a=n(1151);const c={title:"Interacting with the blockchain",slug:"/building-on-lisk/ethers",description:"Documentation for using ethers.js, a JavaScript library for EVM-compatible blockchain interactions. This page covers installation, setup, connecting to the Lisk network, reading and writing blockchain data, and interacting with smart contracts.",keywords:["ethers.js","JavaScript library","Lisk network","Lisk mainnet","Lisk testnet","smart contracts","EVM-compatible","blockchain","JsonRpcProvider","Signer","ABI","interacting with smart contract"]},r="Interacting with the blockchain with ethers.js",o={id:"building-on-lisk/interacting-with-the-blockchain",title:"Interacting with the blockchain",description:"Documentation for using ethers.js, a JavaScript library for EVM-compatible blockchain interactions. This page covers installation, setup, connecting to the Lisk network, reading and writing blockchain data, and interacting with smart contracts.",source:"@site/docs/building-on-lisk/interacting-with-the-blockchain.md",sourceDirName:"building-on-lisk",slug:"/building-on-lisk/ethers",permalink:"/lisk-documentation/building-on-lisk/ethers",draft:!1,unlisted:!1,editUrl:"https://github.com/LiskHQ/lisk-documentation/tree/main/docs/building-on-lisk/interacting-with-the-blockchain.md",tags:[],version:"current",frontMatter:{title:"Interacting with the blockchain",slug:"/building-on-lisk/ethers",description:"Documentation for using ethers.js, a JavaScript library for EVM-compatible blockchain interactions. This page covers installation, setup, connecting to the Lisk network, reading and writing blockchain data, and interacting with smart contracts.",keywords:["ethers.js","JavaScript library","Lisk network","Lisk mainnet","Lisk testnet","smart contracts","EVM-compatible","blockchain","JsonRpcProvider","Signer","ABI","interacting with smart contract"]},sidebar:"documentationSidebar",previous:{title:"Deploying a smart contract with Hardhat",permalink:"/lisk-documentation/building-on-lisk/deploying-a-smart-contract"},next:{title:"Lisk L1->L2 migration guide",permalink:"/lisk-documentation/building-on-lisk/migration-guide"}},s={},l=[{value:"Install",id:"install",level:2},{value:"Setup",id:"setup",level:2},{value:"Connecting to Lisk",id:"connecting-to-lisk",level:2},{value:"Reading data from the blockchain",id:"reading-data-from-the-blockchain",level:2},{value:"Writing data to the blockchain",id:"writing-data-to-the-blockchain",level:2},{value:"Interacting with smart contracts",id:"interacting-with-smart-contracts",level:2}];function d(t){const e={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",hr:"hr",p:"p",pre:"pre",...(0,a.a)(),...t.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(e.h1,{id:"interacting-with-the-blockchain-with-ethersjs",children:"Interacting with the blockchain with ethers.js"}),"\n",(0,i.jsxs)(e.p,{children:[(0,i.jsx)(e.a,{href:"https://docs.ethers.org/v5/",children:"ethers.js"})," is a JavaScript library that allows developers to interact with EVM-compatible blockchain networks."]}),"\n",(0,i.jsx)(e.p,{children:"You can use ethers.js to interact with smart contracts deployed on the Lisk network."}),"\n",(0,i.jsx)(e.hr,{}),"\n",(0,i.jsx)(e.h2,{id:"install",children:"Install"}),"\n",(0,i.jsx)(e.p,{children:"To install ethers.js run the following command:"}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-bash",children:"npm install --save ethers\n"})}),"\n",(0,i.jsx)(e.h2,{id:"setup",children:"Setup"}),"\n",(0,i.jsx)(e.p,{children:"Before you can start using ethers.js, you need to import it into your project."}),"\n",(0,i.jsx)(e.p,{children:"Add the following line of code to the top of your file to import ethers.js:"}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:"const ethers = require('ethers');\n"})}),"\n",(0,i.jsx)(e.h2,{id:"connecting-to-lisk",children:"Connecting to Lisk"}),"\n",(0,i.jsxs)(e.p,{children:["You can connect to Lisk by instantiating a new ethers.js ",(0,i.jsx)(e.code,{children:"JsonRpcProvider"})," object with a RPC URL of the Lisk network:"]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:"const ethers = require('ethers');\n\nconst url = 'https://rpc.sepolia-api.lisk.com';\nconst provider = new ethers.providers.JsonRpcProvider(url);\n"})}),"\n",(0,i.jsx)(e.h2,{id:"reading-data-from-the-blockchain",children:"Reading data from the blockchain"}),"\n",(0,i.jsx)(e.p,{children:"Once you have created a provider, you can use it to read data from the Lisk network."}),"\n",(0,i.jsxs)(e.p,{children:["For example, you can use the ",(0,i.jsx)(e.code,{children:"getBlockNumber"})," method to get the latest block:"]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:"async function getLatestBlock() {\n const latestBlock = await provider.getBlockNumber();\n console.log(latestBlock);\n}\n"})}),"\n",(0,i.jsx)(e.h2,{id:"writing-data-to-the-blockchain",children:"Writing data to the blockchain"}),"\n",(0,i.jsxs)(e.p,{children:["In order to write data to the Lisk network, you need to create a ",(0,i.jsx)(e.code,{children:"Signer"}),"."]}),"\n",(0,i.jsxs)(e.p,{children:["You can create a ",(0,i.jsx)(e.code,{children:"Signer"})," by instantiating a new ethers.js ",(0,i.jsx)(e.code,{children:"Wallet"})," object, providing it with a private key and ",(0,i.jsx)(e.code,{children:"Provider"}),"."]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:"const privateKey = 'PRIVATE_KEY';\nconst signer = new ethers.Wallet(privateKey, provider);\n"})}),"\n",(0,i.jsx)(e.admonition,{type:"info",children:(0,i.jsxs)(e.p,{children:[(0,i.jsx)(e.code,{children:"PRIVATE_KEY"})," is the private key of the wallet to use when creating the signer."]})}),"\n",(0,i.jsx)(e.h2,{id:"interacting-with-smart-contracts",children:"Interacting with smart contracts"}),"\n",(0,i.jsxs)(e.p,{children:["You can use ethers.js to interact with a smart contract on Lisk by instantiating a ",(0,i.jsx)(e.code,{children:"Contract"})," object using the ABI and address of a deployed contract:"]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:'const abi = [\n\u2026 // ABI of deployed contract\n];\n\nconst contractAddress = "CONTRACT_ADDRESS"\n\n// read only\nconst contract = new ethers.Contract(contractAddress, abi, provider);\n'})}),"\n",(0,i.jsxs)(e.p,{children:["For write-only contracts, provide a ",(0,i.jsx)(e.code,{children:"Signer"})," object instead of a ",(0,i.jsx)(e.code,{children:"Provider"})," object:"]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:"// write only\nconst contract = new ethers.Contract(contractAddress, abi, signer);\n"})}),"\n",(0,i.jsx)(e.admonition,{type:"info",children:(0,i.jsxs)(e.p,{children:[(0,i.jsx)(e.code,{children:"CONTRACT_ADDRESS"})," is the address of the deployed contract."]})}),"\n",(0,i.jsxs)(e.p,{children:["Once you have created a ",(0,i.jsx)(e.code,{children:"Contract"})," object, you can use it to call desired methods on the smart contract:"]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-javascript",children:"async function setValue(value) {\n const tx = await contract.set(value);\n console.log(tx.hash);\n}\n\nasync function getValue() {\n const value = await contract.get();\n console.log(value.toString());\n}\n"})})]})}function h(t={}){const{wrapper:e}={...(0,a.a)(),...t.components};return e?(0,i.jsx)(e,{...t,children:(0,i.jsx)(d,{...t})}):d(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>o,a:()=>r});var i=n(7294);const a={},c=i.createContext(a);function r(t){const e=i.useContext(c);return i.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function o(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(a):t.components||a:r(t.components),i.createElement(c.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/0c54d7a4.b2e63e7e.js b/assets/js/0c54d7a4.b2e63e7e.js new file mode 100644 index 000000000..323277fb9 --- /dev/null +++ b/assets/js/0c54d7a4.b2e63e7e.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunklisk_docs=self.webpackChunklisk_docs||[]).push([[422],{6680:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>o,contentTitle:()=>r,default:()=>h,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var i=n(5893),c=n(1151);const a={title:"Interacting with the blockchain",slug:"/building-on-lisk/ethers",description:"Documentation for using ethers.js, a JavaScript library for EVM-compatible blockchain interactions. This page covers installation, setup, connecting to the Lisk network, reading and writing blockchain data, and interacting with smart contracts.",keywords:["ethers.js","JavaScript library","Lisk network","Lisk mainnet","Lisk testnet","smart contracts","EVM-compatible","blockchain","JsonRpcProvider","Signer","ABI","interacting with smart contract"]},r="Interacting with the blockchain with ethers.js",s={id:"building-on-lisk/interacting-with-the-blockchain",title:"Interacting with the blockchain",description:"Documentation for using ethers.js, a JavaScript library for EVM-compatible blockchain interactions. This page covers installation, setup, connecting to the Lisk network, reading and writing blockchain data, and interacting with smart contracts.",source:"@site/docs/building-on-lisk/interacting-with-the-blockchain.md",sourceDirName:"building-on-lisk",slug:"/building-on-lisk/ethers",permalink:"/lisk-documentation/building-on-lisk/ethers",draft:!1,unlisted:!1,editUrl:"https://github.com/LiskHQ/lisk-documentation/tree/main/docs/building-on-lisk/interacting-with-the-blockchain.md",tags:[],version:"current",frontMatter:{title:"Interacting with the blockchain",slug:"/building-on-lisk/ethers",description:"Documentation for using ethers.js, a JavaScript library for EVM-compatible blockchain interactions. This page covers installation, setup, connecting to the Lisk network, reading and writing blockchain data, and interacting with smart contracts.",keywords:["ethers.js","JavaScript library","Lisk network","Lisk mainnet","Lisk testnet","smart contracts","EVM-compatible","blockchain","JsonRpcProvider","Signer","ABI","interacting with smart contract"]},sidebar:"documentationSidebar",previous:{title:"Deploying a smart contract with Hardhat",permalink:"/lisk-documentation/building-on-lisk/deploying-a-smart-contract"},next:{title:"Lisk L1->L2 migration guide",permalink:"/lisk-documentation/building-on-lisk/migration-guide"}},o={},l=[{value:"Install",id:"install",level:2},{value:"Setup",id:"setup",level:2},{value:"Connecting to Lisk",id:"connecting-to-lisk",level:2},{value:"Reading data from the blockchain",id:"reading-data-from-the-blockchain",level:2},{value:"Writing data to the blockchain",id:"writing-data-to-the-blockchain",level:2},{value:"Interacting with smart contracts",id:"interacting-with-smart-contracts",level:2}];function d(e){const t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,c.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h1,{id:"interacting-with-the-blockchain-with-ethersjs",children:"Interacting with the blockchain with ethers.js"}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.a,{href:"https://docs.ethers.org/v5/",children:"ethers.js"})," is a JavaScript library that allows developers to interact with EVM-compatible blockchain networks."]}),"\n",(0,i.jsx)(t.p,{children:"You can use ethers.js to interact with smart contracts deployed on the Lisk network."}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,i.jsx)(t.p,{children:"To install ethers.js run the following command:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"npm install --save ethers\n"})}),"\n",(0,i.jsx)(t.h2,{id:"setup",children:"Setup"}),"\n",(0,i.jsx)(t.p,{children:"Before you can start using ethers.js, you need to import it into your project."}),"\n",(0,i.jsx)(t.p,{children:"Add the following line of code to the top of your file to import ethers.js:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"const ethers = require('ethers');\n"})}),"\n",(0,i.jsx)(t.h2,{id:"connecting-to-lisk",children:"Connecting to Lisk"}),"\n",(0,i.jsxs)(t.p,{children:["You can connect to Lisk by instantiating a new ethers.js ",(0,i.jsx)(t.code,{children:"JsonRpcProvider"})," object with a RPC URL of the Lisk network:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"const ethers = require('ethers');\n\nconst url = 'https://rpc.sepolia-api.lisk.com';\nconst provider = new ethers.JsonRpcProvider(url);\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:["A ",(0,i.jsx)(t.strong,{children:"Provider"})," (in ethers.js) is a class which provides an abstraction for a connection to the Ethereum Network. It provides read-only access to the Blockchain and its status."]})}),"\n",(0,i.jsx)(t.h2,{id:"reading-data-from-the-blockchain",children:"Reading data from the blockchain"}),"\n",(0,i.jsx)(t.p,{children:"Once you have created a provider, you can use it to read data from the Lisk network."}),"\n",(0,i.jsxs)(t.p,{children:["For example, you can use the ",(0,i.jsx)(t.code,{children:"getBlockNumber"})," method to get the latest block:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"async function getLatestBlock() {\n const latestBlock = await provider.getBlockNumber();\n console.log(latestBlock);\n}\n"})}),"\n",(0,i.jsx)(t.h2,{id:"writing-data-to-the-blockchain",children:"Writing data to the blockchain"}),"\n",(0,i.jsxs)(t.p,{children:["In order to write data to the Lisk network, you need to create a ",(0,i.jsx)(t.code,{children:"Signer"}),"."]}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:["A ",(0,i.jsx)(t.strong,{children:"Signer"})," is a class which (usually) in some way directly or indirectly has access to a private key, which can sign messages and transactions to authorize the network to charge your account ether to perform operations."]})}),"\n",(0,i.jsxs)(t.p,{children:["You can create a ",(0,i.jsx)(t.code,{children:"Signer"})," by instantiating a new ethers.js ",(0,i.jsx)(t.code,{children:"Wallet"})," object, providing it with a private key and ",(0,i.jsx)(t.code,{children:"Provider"}),"."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:'const privateKey = \'PRIVATE_KEY\';\nconst signer = new ethers.Wallet(privateKey, provider);\n// Send 1 ether to an ens name.\nconst tx = signer.sendTransaction({\n to: "lisk.eth",\n value: ethers.utils.parseEther("1.0")\n});\n'})}),"\n",(0,i.jsx)(t.admonition,{type:"info",children:(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"PRIVATE_KEY"})," is the private key of the wallet to use when creating the signer."]})}),"\n",(0,i.jsx)(t.h2,{id:"interacting-with-smart-contracts",children:"Interacting with smart contracts"}),"\n",(0,i.jsxs)(t.p,{children:["You can use ethers.js to interact with a smart contract on Lisk by instantiating a ",(0,i.jsx)(t.code,{children:"Contract"})," object using the ABI and address of a deployed contract:"]}),"\n",(0,i.jsxs)(t.admonition,{type:"tip",children:[(0,i.jsxs)(t.p,{children:["The ABI of a contract can be found on the respective contract page in ",(0,i.jsx)(t.a,{href:"https://sepolia-blockscout.lisk.com/",children:"BlockScout"}),"."]}),(0,i.jsxs)(t.p,{children:["For example, you can find the ABI for the ",(0,i.jsx)(t.code,{children:"Hello"})," contract ",(0,i.jsx)(t.a,{href:"https://sepolia-blockscout.lisk.com/address/0xb18eb752813c2fbedfdf2be6e5e842a85a3b8539?tab=contact_code",children:"here"}),". Just scroll down to ",(0,i.jsx)(t.code,{children:"Contract ABI"}),"."]})]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:'const abi = [\n\u2026 // ABI of deployed contract\n];\n\nconst contractAddress = "CONTRACT_ADDRESS"\n\n// read only\nconst contract = new ethers.Contract(contractAddress, abi, provider);\n'})}),"\n",(0,i.jsx)(t.admonition,{type:"info",children:(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"CONTRACT_ADDRESS"})," is the address of the deployed contract."]})}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:["A ",(0,i.jsx)(t.strong,{children:"Contract"})," (in ethers.js) is an abstraction which represents a connection to a specific contract on the Lisk Network, so that applications can use it like a normal JavaScript object."]})}),"\n",(0,i.jsxs)(t.p,{children:["For reading and writing to contracts, provide a ",(0,i.jsx)(t.code,{children:"Signer"})," object instead of a ",(0,i.jsx)(t.code,{children:"Provider"})," object:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"// read & write \nconst contract = new ethers.Contract(contractAddress, abi, signer);\n"})}),"\n",(0,i.jsxs)(t.p,{children:["Once you have created a ",(0,i.jsx)(t.code,{children:"Contract"})," object, you can use it to call desired methods on the smart contract:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:'async function createHello(message) {\n const tx = await contract.createHello(message);\n return tx.hash;\n}\n \nasync function getHello() {\n const value = await contract.message("0x3C46A11471f285E36EE8d089473ce98269D1b081");\n return value.toString();\n}\n'})}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["For an overview of existing public functions for the contract, please check the ",(0,i.jsx)(t.a,{href:"https://sepolia-blockscout.lisk.com/address/0xb18eb752813c2fbedfdf2be6e5e842a85a3b8539?tab=read_contract",children:"Read Contract"})," and ",(0,i.jsx)(t.a,{href:"https://sepolia-blockscout.lisk.com/address/0xb18eb752813c2fbedfdf2be6e5e842a85a3b8539?tab=write_contract",children:"Write Contract"})," tabs for the specific contract."]})})]})}function h(e={}){const{wrapper:t}={...(0,c.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>r});var i=n(7294);const c={},a=i.createContext(c);function r(e){const t=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(c):e.components||c:r(e.components),i.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/runtime~main.b1737035.js b/assets/js/runtime~main.1657047f.js similarity index 98% rename from assets/js/runtime~main.b1737035.js rename to assets/js/runtime~main.1657047f.js index deb210fd7..3dd5a1fbc 100644 --- a/assets/js/runtime~main.b1737035.js +++ b/assets/js/runtime~main.1657047f.js @@ -1 +1 @@ -(()=>{"use strict";var e,t,r,a,o,n={},c={};function f(e){var t=c[e];if(void 0!==t)return t.exports;var r=c[e]={exports:{}};return n[e].call(r.exports,r,r.exports,f),r.exports}f.m=n,e=[],f.O=(t,r,a,o)=>{if(!r){var n=1/0;for(d=0;d=o)&&Object.keys(f.O).every((e=>f.O[e](r[i])))?r.splice(i--,1):(c=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[r,a,o]},f.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return f.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,f.t=function(e,a){if(1&a&&(e=this(e)),8&a)return e;if("object"==typeof e&&e){if(4&a&&e.__esModule)return e;if(16&a&&"function"==typeof e.then)return e}var o=Object.create(null);f.r(o);var n={};t=t||[null,r({}),r([]),r(r)];for(var c=2&a&&e;"object"==typeof c&&!~t.indexOf(c);c=r(c))Object.getOwnPropertyNames(c).forEach((t=>n[t]=()=>e[t]));return n.default=()=>e,f.d(o,n),o},f.d=(e,t)=>{for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.f={},f.e=e=>Promise.all(Object.keys(f.f).reduce(((t,r)=>(f.f[r](e,t),t)),[])),f.u=e=>"assets/js/"+({6:"2ef85f89",53:"935f2afb",68:"0eafa1eb",85:"1f391b9e",184:"6ce766bb",240:"90210d68",318:"b2059c63",368:"a94703ab",383:"0480cc7e",388:"1224f3e7",414:"393be207",421:"bcc5765f",422:"0c54d7a4",444:"6183c0e3",445:"951748bc",462:"f58537f1",518:"a7bd4aaa",568:"dad52d3b",661:"5e95c892",671:"0e384e19",817:"14eb3368",918:"17896441"}[e]||e)+"."+{6:"cbf2faff",53:"12ec571e",68:"06991558",85:"34f79b08",184:"8d9037d1",240:"4381688d",318:"31821c9d",368:"5c7c46ba",383:"07513c48",388:"f648b06f",414:"6280be6b",421:"1591268c",422:"a9badad3",444:"c3a6057f",445:"b1639ec1",462:"81742591",518:"c2569488",568:"77f099aa",661:"15d8fdf1",671:"d4de47e6",674:"5283d329",772:"7b0f19ea",817:"c8cc9442",918:"9169ebd0"}[e]+".js",f.miniCssF=e=>{},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a={},o="lisk-docs:",f.l=(e,t,r,n)=>{if(a[e])a[e].push(t);else{var c,i;if(void 0!==r)for(var b=document.getElementsByTagName("script"),d=0;d{c.onerror=c.onload=null,clearTimeout(s);var o=a[e];if(delete a[e],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach((e=>e(r))),t)return t(r)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=l.bind(null,c.onerror),c.onload=l.bind(null,c.onload),i&&document.head.appendChild(c)}},f.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.p="/lisk-documentation/",f.gca=function(e){return e={17896441:"918","2ef85f89":"6","935f2afb":"53","0eafa1eb":"68","1f391b9e":"85","6ce766bb":"184","90210d68":"240",b2059c63:"318",a94703ab:"368","0480cc7e":"383","1224f3e7":"388","393be207":"414",bcc5765f:"421","0c54d7a4":"422","6183c0e3":"444","951748bc":"445",f58537f1:"462",a7bd4aaa:"518",dad52d3b:"568","5e95c892":"661","0e384e19":"671","14eb3368":"817"}[e]||e,f.p+f.u(e)},(()=>{var e={303:0,532:0};f.f.j=(t,r)=>{var a=f.o(e,t)?e[t]:void 0;if(0!==a)if(a)r.push(a[2]);else if(/^(303|532)$/.test(t))e[t]=0;else{var o=new Promise(((r,o)=>a=e[t]=[r,o]));r.push(a[2]=o);var n=f.p+f.u(t),c=new Error;f.l(n,(r=>{if(f.o(e,t)&&(0!==(a=e[t])&&(e[t]=void 0),a)){var o=r&&("load"===r.type?"missing":r.type),n=r&&r.target&&r.target.src;c.message="Loading chunk "+t+" failed.\n("+o+": "+n+")",c.name="ChunkLoadError",c.type=o,c.request=n,a[1](c)}}),"chunk-"+t,t)}},f.O.j=t=>0===e[t];var t=(t,r)=>{var a,o,n=r[0],c=r[1],i=r[2],b=0;if(n.some((t=>0!==e[t]))){for(a in c)f.o(c,a)&&(f.m[a]=c[a]);if(i)var d=i(f)}for(t&&t(r);b{"use strict";var e,t,r,a,o,n={},c={};function f(e){var t=c[e];if(void 0!==t)return t.exports;var r=c[e]={exports:{}};return n[e].call(r.exports,r,r.exports,f),r.exports}f.m=n,e=[],f.O=(t,r,a,o)=>{if(!r){var n=1/0;for(d=0;d=o)&&Object.keys(f.O).every((e=>f.O[e](r[i])))?r.splice(i--,1):(c=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[r,a,o]},f.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return f.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,f.t=function(e,a){if(1&a&&(e=this(e)),8&a)return e;if("object"==typeof e&&e){if(4&a&&e.__esModule)return e;if(16&a&&"function"==typeof e.then)return e}var o=Object.create(null);f.r(o);var n={};t=t||[null,r({}),r([]),r(r)];for(var c=2&a&&e;"object"==typeof c&&!~t.indexOf(c);c=r(c))Object.getOwnPropertyNames(c).forEach((t=>n[t]=()=>e[t]));return n.default=()=>e,f.d(o,n),o},f.d=(e,t)=>{for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.f={},f.e=e=>Promise.all(Object.keys(f.f).reduce(((t,r)=>(f.f[r](e,t),t)),[])),f.u=e=>"assets/js/"+({6:"2ef85f89",53:"935f2afb",68:"0eafa1eb",85:"1f391b9e",184:"6ce766bb",240:"90210d68",318:"b2059c63",368:"a94703ab",383:"0480cc7e",388:"1224f3e7",414:"393be207",421:"bcc5765f",422:"0c54d7a4",444:"6183c0e3",445:"951748bc",462:"f58537f1",518:"a7bd4aaa",568:"dad52d3b",661:"5e95c892",671:"0e384e19",817:"14eb3368",918:"17896441"}[e]||e)+"."+{6:"cbf2faff",53:"12ec571e",68:"06991558",85:"34f79b08",184:"8d9037d1",240:"4381688d",318:"31821c9d",368:"5c7c46ba",383:"07513c48",388:"f648b06f",414:"6280be6b",421:"1591268c",422:"b2e63e7e",444:"c3a6057f",445:"b1639ec1",462:"81742591",518:"c2569488",568:"77f099aa",661:"15d8fdf1",671:"d4de47e6",674:"5283d329",772:"7b0f19ea",817:"c8cc9442",918:"9169ebd0"}[e]+".js",f.miniCssF=e=>{},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a={},o="lisk-docs:",f.l=(e,t,r,n)=>{if(a[e])a[e].push(t);else{var c,i;if(void 0!==r)for(var b=document.getElementsByTagName("script"),d=0;d{c.onerror=c.onload=null,clearTimeout(s);var o=a[e];if(delete a[e],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach((e=>e(r))),t)return t(r)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=l.bind(null,c.onerror),c.onload=l.bind(null,c.onload),i&&document.head.appendChild(c)}},f.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.p="/lisk-documentation/",f.gca=function(e){return e={17896441:"918","2ef85f89":"6","935f2afb":"53","0eafa1eb":"68","1f391b9e":"85","6ce766bb":"184","90210d68":"240",b2059c63:"318",a94703ab:"368","0480cc7e":"383","1224f3e7":"388","393be207":"414",bcc5765f:"421","0c54d7a4":"422","6183c0e3":"444","951748bc":"445",f58537f1:"462",a7bd4aaa:"518",dad52d3b:"568","5e95c892":"661","0e384e19":"671","14eb3368":"817"}[e]||e,f.p+f.u(e)},(()=>{var e={303:0,532:0};f.f.j=(t,r)=>{var a=f.o(e,t)?e[t]:void 0;if(0!==a)if(a)r.push(a[2]);else if(/^(303|532)$/.test(t))e[t]=0;else{var o=new Promise(((r,o)=>a=e[t]=[r,o]));r.push(a[2]=o);var n=f.p+f.u(t),c=new Error;f.l(n,(r=>{if(f.o(e,t)&&(0!==(a=e[t])&&(e[t]=void 0),a)){var o=r&&("load"===r.type?"missing":r.type),n=r&&r.target&&r.target.src;c.message="Loading chunk "+t+" failed.\n("+o+": "+n+")",c.name="ChunkLoadError",c.type=o,c.request=n,a[1](c)}}),"chunk-"+t,t)}},f.O.j=t=>0===e[t];var t=(t,r)=>{var a,o,n=r[0],c=r[1],i=r[2],b=0;if(n.some((t=>0!==e[t]))){for(a in c)f.o(c,a)&&(f.m[a]=c[a]);if(i)var d=i(f)}for(t&&t(r);b Deploying a smart contract with Hardhat | Lisk Documentation - + diff --git a/building-on-lisk/ethers.html b/building-on-lisk/ethers.html index e000b0ff9..538d1803c 100644 --- a/building-on-lisk/ethers.html +++ b/building-on-lisk/ethers.html @@ -4,7 +4,7 @@ Interacting with the blockchain | Lisk Documentation - + @@ -24,24 +24,29 @@

Setup
const ethers = require('ethers');

Connecting to Lisk

You can connect to Lisk by instantiating a new ethers.js JsonRpcProvider object with a RPC URL of the Lisk network:

-
const ethers = require('ethers');

const url = 'https://rpc.sepolia-api.lisk.com';
const provider = new ethers.providers.JsonRpcProvider(url);
+
const ethers = require('ethers');

const url = 'https://rpc.sepolia-api.lisk.com';
const provider = new ethers.JsonRpcProvider(url);
+
note

A Provider (in ethers.js) is a class which provides an abstraction for a connection to the Ethereum Network. It provides read-only access to the Blockchain and its status.

Reading data from the blockchain

Once you have created a provider, you can use it to read data from the Lisk network.

For example, you can use the getBlockNumber method to get the latest block:

async function getLatestBlock() {
const latestBlock = await provider.getBlockNumber();
console.log(latestBlock);
}

Writing data to the blockchain

In order to write data to the Lisk network, you need to create a Signer.

+
note

A Signer is a class which (usually) in some way directly or indirectly has access to a private key, which can sign messages and transactions to authorize the network to charge your account ether to perform operations.

You can create a Signer by instantiating a new ethers.js Wallet object, providing it with a private key and Provider.

-
const privateKey = 'PRIVATE_KEY';
const signer = new ethers.Wallet(privateKey, provider);
+
const privateKey = 'PRIVATE_KEY';
const signer = new ethers.Wallet(privateKey, provider);
// Send 1 ether to an ens name.
const tx = signer.sendTransaction({
to: "lisk.eth",
value: ethers.utils.parseEther("1.0")
});
info

PRIVATE_KEY is the private key of the wallet to use when creating the signer.

Interacting with smart contracts

You can use ethers.js to interact with a smart contract on Lisk by instantiating a Contract object using the ABI and address of a deployed contract:

+
tip

The ABI of a contract can be found on the respective contract page in BlockScout.

For example, you can find the ABI for the Hello contract here. Just scroll down to Contract ABI.

const abi = [
// ABI of deployed contract
];

const contractAddress = "CONTRACT_ADDRESS"

// read only
const contract = new ethers.Contract(contractAddress, abi, provider);
-

For write-only contracts, provide a Signer object instead of a Provider object:

-
// write only
const contract = new ethers.Contract(contractAddress, abi, signer);
info

CONTRACT_ADDRESS is the address of the deployed contract.

+
note

A Contract (in ethers.js) is an abstraction which represents a connection to a specific contract on the Lisk Network, so that applications can use it like a normal JavaScript object.

+

For reading and writing to contracts, provide a Signer object instead of a Provider object:

+
// read & write 
const contract = new ethers.Contract(contractAddress, abi, signer);

Once you have created a Contract object, you can use it to call desired methods on the smart contract:

-
async function setValue(value) {
const tx = await contract.set(value);
console.log(tx.hash);
}

async function getValue() {
const value = await contract.get();
console.log(value.toString());
}