diff --git a/404.html b/404.html index e7d120e6f..6d64dd2fa 100644 --- a/404.html +++ b/404.html @@ -4,7 +4,7 @@
const ethers = require('ethers');
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);
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.
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);
}
In order to write data to the Lisk network, you need to create a Signer
.
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")
});
PRIVATE_KEY
is the private key of the wallet to use when creating the signer.
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:
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);
CONTRACT_ADDRESS
is the address of the deployed contract.
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());
}