diff --git a/.snippets/code/ethers-contract-local/reset.js b/.snippets/code/ethers-contract-local/reset.js deleted file mode 100644 index 749de016e..000000000 --- a/.snippets/code/ethers-contract-local/reset.js +++ /dev/null @@ -1,38 +0,0 @@ -const ethers = require('ethers'); -const { abi } = require('./compile'); - -const providerRPC = { - development: { - name: 'moonbeam-development', - rpc: 'http://localhost:9944', - chainId: 1281, - }, - moonbase: { - name: 'moonbase-alpha', - rpc: 'https://rpc.api.moonbase.moonbeam.network', - chainId: 1287, - }, -}; -const provider = new ethers.JsonRpcProvider(providerRPC.development.rpc, { - chainId: providerRPC.development.chainId, - name: providerRPC.development.name, -}); // Change to correct network - -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', -}; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; - -let wallet = new ethers.Wallet(account_from.privateKey, provider); - -const incrementer = new ethers.Contract(contractAddress, abi, wallet); -const reset = async () => { - console.log(`Calling the reset function in contract at address: ${contractAddress}`); - - const createReceipt = await incrementer.reset(); - await createReceipt.wait(); - - console.log(`Tx successful with hash: ${createReceipt.hash}`); -}; - -reset(); \ No newline at end of file diff --git a/.snippets/code/ethers-contract-local/deploy.js b/.snippets/code/ethers-js-contract/deploy.js similarity index 58% rename from .snippets/code/ethers-contract-local/deploy.js rename to .snippets/code/ethers-js-contract/deploy.js index 8ad6a8e62..ef32ab10d 100644 --- a/.snippets/code/ethers-contract-local/deploy.js +++ b/.snippets/code/ethers-js-contract/deploy.js @@ -1,6 +1,8 @@ +// Import ethers and compile const ethers = require('ethers'); const contractFile = require('./compile'); +// Define network configurations const providerRPC = { development: { name: 'moonbeam-development', @@ -13,28 +15,36 @@ const providerRPC = { chainId: 1287, }, }; -const provider = new ethers.JsonRpcProvider(providerRPC.development.rpc, { - chainId: providerRPC.development.chainId, - name: providerRPC.development.name, + +// Create ethers provider +const provider = new ethers.JsonRpcProvider(providerRPC.moonbase.rpc, { + chainId: providerRPC.moonbase.chainId, + name: providerRPC.moonbase.name, }); // Change to correct network -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +// Define accounts and wallet +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); + +// Load contract info const bytecode = contractFile.evm.bytecode.object; const abi = contractFile.abi; -let wallet = new ethers.Wallet(account_from.privateKey, provider); - +// Create contract instance with signer const incrementer = new ethers.ContractFactory(abi, bytecode, wallet); +// Create deploy function const deploy = async () => { console.log(`Attempting to deploy from account: ${wallet.address}`); + // Send tx (initial value set to 5) and wait for receipt const contract = await incrementer.deploy(5); const txReceipt = await contract.deploymentTransaction().wait(); console.log(`Contract deployed at address: ${txReceipt.contractAddress}`); }; -deploy(); \ No newline at end of file +// Call the deploy function +deploy(); diff --git a/.snippets/code/ethers-contract-local/get.js b/.snippets/code/ethers-js-contract/get.js similarity index 62% rename from .snippets/code/ethers-contract-local/get.js rename to .snippets/code/ethers-js-contract/get.js index 776eecb6a..834551ee8 100644 --- a/.snippets/code/ethers-contract-local/get.js +++ b/.snippets/code/ethers-js-contract/get.js @@ -1,6 +1,8 @@ +// Import ethers and compile const ethers = require('ethers'); const { abi } = require('./compile'); +// Define network configurations const providerRPC = { development: { name: 'moonbeam-development', @@ -13,21 +15,27 @@ const providerRPC = { chainId: 1287, }, }; -const provider = new ethers.JsonRpcProvider(providerRPC.development.rpc, { - chainId: providerRPC.development.chainId, - name: providerRPC.development.name, + +const provider = new ethers.JsonRpcProvider(providerRPC.moonbase.rpc, { + chainId: providerRPC.moonbase.chainId, + name: providerRPC.moonbase.name, }); // Change to correct network -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +// Contract address variable +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; +// Create contract instance const incrementer = new ethers.Contract(contractAddress, abi, provider); +// Create get function const get = async () => { console.log(`Making a call to contract at address: ${contractAddress}`); + // Call contract const data = await incrementer.number(); console.log(`The current number stored is: ${data}`); }; -get(); \ No newline at end of file +// Call get function +get(); diff --git a/.snippets/code/ethers-contract-local/increment.js b/.snippets/code/ethers-js-contract/increment.js similarity index 55% rename from .snippets/code/ethers-contract-local/increment.js rename to .snippets/code/ethers-js-contract/increment.js index 8baeee3c0..21c146b1a 100644 --- a/.snippets/code/ethers-contract-local/increment.js +++ b/.snippets/code/ethers-js-contract/increment.js @@ -1,6 +1,8 @@ +// Import ethers and compile const ethers = require('ethers'); const { abi } = require('./compile'); +// Define network configurations const providerRPC = { development: { name: 'moonbeam-development', @@ -13,29 +15,38 @@ const providerRPC = { chainId: 1287, }, }; -const provider = new ethers.JsonRpcProvider(providerRPC.development.rpc, { - chainId: providerRPC.development.chainId, - name: providerRPC.development.name, + +// Create ethers provider +const provider = new ethers.JsonRpcProvider(providerRPC.moonbase.rpc, { + chainId: providerRPC.moonbase.chainId, + name: providerRPC.moonbase.name, }); // Change to correct network -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +// Create variables +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; const _value = 3; -let wallet = new ethers.Wallet(account_from.privateKey, provider); +// Create wallet +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); +// Create contract instance with signer const incrementer = new ethers.Contract(contractAddress, abi, wallet); + +// Create reset function const increment = async () => { console.log( `Calling the increment by ${_value} function in contract at address: ${contractAddress}` ); + // Sign and send tx and wait for receipt const createReceipt = await incrementer.increment(_value); await createReceipt.wait(); console.log(`Tx successful with hash: ${createReceipt.hash}`); }; -increment(); \ No newline at end of file +// Call the reset function +increment(); diff --git a/.snippets/code/ethers-js-contract/reset.js b/.snippets/code/ethers-js-contract/reset.js new file mode 100644 index 000000000..4127e94f0 --- /dev/null +++ b/.snippets/code/ethers-js-contract/reset.js @@ -0,0 +1,51 @@ +// Import ethers and compile +const ethers = require('ethers'); +const { abi } = require('./compile'); + +// Define network configurations +const providerRPC = { + development: { + name: 'moonbeam-development', + rpc: 'http://localhost:9944', + chainId: 1281, + }, + moonbase: { + name: 'moonbase-alpha', + rpc: 'https://rpc.api.moonbase.moonbeam.network', + chainId: 1287, + }, +}; + +// Create ethers provider +const provider = new ethers.JsonRpcProvider(providerRPC.moonbase.rpc, { + chainId: providerRPC.moonbase.chainId, + name: providerRPC.moonbase.name, +}); // Change to correct network + +// Create variables +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', +}; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; + +// Create wallet +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); + +// Create contract instance with signer +const incrementer = new ethers.Contract(contractAddress, abi, wallet); + +// Create reset function +const reset = async () => { + console.log( + `Calling the reset function in contract at address: ${contractAddress}` + ); + + // Sign and send tx and wait for receipt + const createReceipt = await incrementer.reset(); + await createReceipt.wait(); + + console.log(`Tx successful with hash: ${createReceipt.hash}`); +}; + +// Call the reset function +reset(); diff --git a/.snippets/code/ethers-js-tx/balances.js b/.snippets/code/ethers-js-tx/balances.js new file mode 100644 index 000000000..69895bc34 --- /dev/null +++ b/.snippets/code/ethers-js-tx/balances.js @@ -0,0 +1,41 @@ +// Import ethers +const ethers = require('ethers'); + +// Define network configurations +const providerRPC = { + development: { + name: 'moonbeam-development', + rpc: 'http://localhost:9944', + chainId: 1281, + }, + moonbase: { + name: 'moonbase-alpha', + rpc: 'https://rpc.api.moonbase.moonbeam.network', + chainId: 1287, + }, +}; + +// Create ethers provider +const provider = new ethers.JsonRpcProvider(providerRPC.moonbase.rpc, { + chainId: providerRPC.moonbase.chainId, + name: providerRPC.moonbase.name, +}); // Change to correct network + +// Define addresses +const addressFrom = 'INSERT_FROM_ADDRESS'; +const addressTo = 'INSERT_TO_ADDRESS'; + +// Create balances function +const balances = async () => { + // 6. Fetch balances + const balanceFrom = ethers.formatEther( + await provider.getBalance(addressFrom) + ); + const balanceTo = ethers.formatEther(await provider.getBalance(addressTo)); + + console.log(`The balance of ${addressFrom} is: ${balanceFrom} DEV`); + console.log(`The balance of ${addressTo} is: ${balanceTo} DEV`); +}; + +// Call the balances function +balances(); diff --git a/.snippets/code/ethers-js-tx/transaction.js b/.snippets/code/ethers-js-tx/transaction.js new file mode 100644 index 000000000..007538f97 --- /dev/null +++ b/.snippets/code/ethers-js-tx/transaction.js @@ -0,0 +1,49 @@ +// Import ethers +const ethers = require('ethers'); + +// Define network configurations +const providerRPC = { + development: { + name: 'moonbeam-development', + rpc: 'http://localhost:9944', + chainId: 1281, + }, + moonbase: { + name: 'moonbase-alpha', + rpc: 'https://rpc.api.moonbase.moonbeam.network', + chainId: 1287, + }, +}; +// Create ethers provider +const provider = new ethers.JsonRpcProvider(providerRPC.moonbase.rpc, { + chainId: providerRPC.moonbase.chainId, + name: providerRPC.moonbase.name, +}); // Change to correct network + +// Define accounts and wallet +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', +}; +const addressTo = 'INSERT_TO_ADDRESS'; +const wallet = new ethers.Wallet(accountFrom.privateKey, provider); + +// Create send function +const send = async () => { + console.log( + `Attempting to send transaction from ${wallet.address} to ${addressTo}` + ); + + // Create transaction + const tx = { + to: addressTo, + value: ethers.parseEther('1'), + }; + + // Send transaction and get hash + const createReceipt = await wallet.sendTransaction(tx); + await createReceipt.wait(); + console.log(`Transaction successful with hash: ${createReceipt.hash}`); +}; + +// Call the send function +send(); diff --git a/.snippets/code/ethers-tx-local/balances.js b/.snippets/code/ethers-tx-local/balances.js deleted file mode 100644 index 7195e510e..000000000 --- a/.snippets/code/ethers-tx-local/balances.js +++ /dev/null @@ -1,32 +0,0 @@ -const ethers = require('ethers'); - -const providerRPC = { - development: { - name: 'moonbeam-development', - rpc: 'http://localhost:9944', - chainId: 1281, - }, - moonbase: { - name: 'moonbase-alpha', - rpc: 'https://rpc.api.moonbase.moonbeam.network', - chainId: 1287, - }, -}; -const provider = new ethers.JsonRpcProvider(providerRPC.development.rpc, { - chainId: providerRPC.development.chainId, - name: providerRPC.development.name, -}); // Change to correct network - -const addressFrom = 'ADDRESS-FROM-HERE'; -const addressTo = 'ADDRESS-TO-HERE'; - -const balances = async () => { - const balanceFrom = ethers.formatEther(await provider.getBalance(addressFrom)); - - const balanceTo = ethers.formatEther(await provider.getBalance(addressTo)); - - console.log(`The balance of ${addressFrom} is: ${balanceFrom} ETH`); - console.log(`The balance of ${addressTo} is: ${balanceTo} ETH`); -}; - -balances(); \ No newline at end of file diff --git a/.snippets/code/ethers-tx-local/transaction.js b/.snippets/code/ethers-tx-local/transaction.js deleted file mode 100644 index 5b41eb01d..000000000 --- a/.snippets/code/ethers-tx-local/transaction.js +++ /dev/null @@ -1,40 +0,0 @@ -const ethers = require('ethers'); - -const providerRPC = { - development: { - name: 'moonbeam-development', - rpc: 'http://localhost:9944', - chainId: 1281, - }, - moonbase: { - name: 'moonbase-alpha', - rpc: 'https://rpc.api.moonbase.moonbeam.network', - chainId: 1287, - }, -}; -const provider = new ethers.JsonRpcProvider(providerRPC.development.rpc, { - chainId: providerRPC.development.chainId, - name: providerRPC.development.name, -}); // Change to correct network - -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', -}; -const addressTo = 'ADDRESS-TO-HERE'; - -let wallet = new ethers.Wallet(account_from.privateKey, provider); - -const send = async () => { - console.log(`Attempting to send transaction from ${wallet.address} to ${addressTo}`); - - const tx = { - to: addressTo, - value: ethers.parseEther('1'), - }; - - const createReceipt = await wallet.sendTransaction(tx); - await createReceipt.wait(); - console.log(`Transaction successful with hash: ${createReceipt.hash}`); -}; - -send(); \ No newline at end of file diff --git a/.snippets/code/web3-contract-local/deploy.js b/.snippets/code/web3-contract-local/deploy.js index b04780b7d..0cc0ee1bd 100644 --- a/.snippets/code/web3-contract-local/deploy.js +++ b/.snippets/code/web3-contract-local/deploy.js @@ -1,39 +1,51 @@ +// 1. Import web3 and the contract file + const Web3 = require('web3'); const contractFile = require('./compile'); +// 2. Add the Web3 provider logic here: const providerRPC = { development: 'http://localhost:9944', moonbase: 'https://rpc.api.moonbase.moonbeam.network', }; -const web3 = new Web3(providerRPC.development); // Change to correct network +const web3 = new Web3(providerRPC.moonbase); // Change to correct network -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', - address: 'PUBLIC-ADDRESS-OF-PK-HERE', +// 3. Create address variables +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', + address: 'INSERT_PUBLIC_ADDRESS_OF_PK', }; + +// 4. Get the bytecode and API const bytecode = contractFile.evm.bytecode.object; const abi = contractFile.abi; +// 5. Create deploy function const deploy = async () => { - console.log(`Attempting to deploy from account ${account_from.address}`); + console.log(`Attempting to deploy from account ${accountFrom.address}`); + // 6. Create contract instance const incrementer = new web3.eth.Contract(abi); + // 7. Create constructor tx const incrementerTx = incrementer.deploy({ data: bytecode, arguments: [5], }); + // 8. Sign transacation and send const createTransaction = await web3.eth.accounts.signTransaction( { data: incrementerTx.encodeABI(), gas: await incrementerTx.estimateGas(), }, - account_from.privateKey + accountFrom.privateKey ); + // 9. Send tx and wait for receipt const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction); console.log(`Contract deployed at address: ${createReceipt.contractAddress}`); }; -deploy(); \ No newline at end of file +// 10. Call deploy function +deploy(); diff --git a/.snippets/code/web3-contract-local/get.js b/.snippets/code/web3-contract-local/get.js index a2488c406..4d3a84995 100644 --- a/.snippets/code/web3-contract-local/get.js +++ b/.snippets/code/web3-contract-local/get.js @@ -1,22 +1,29 @@ +// 1. Import Web3js and the contract abi const Web3 = require('web3'); const { abi } = require('./compile'); +// 2. Add the Web3 provider logic here: const providerRPC = { development: 'http://localhost:9944', moonbase: 'https://rpc.api.moonbase.moonbeam.network', }; -const web3 = new Web3(providerRPC.development); // Change to correct network +const web3 = new Web3(providerRPC.moonbase); // Change to correct network -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +// 3. Create address variables +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; +// 4. Create contract instance const incrementer = new web3.eth.Contract(abi, contractAddress); +// 5. Create get function const get = async () => { console.log(`Making a call to contract at address: ${contractAddress}`); + // 6. Call contract const data = await incrementer.methods.number().call(); console.log(`The current number stored is: ${data}`); }; +// 7. Call get function get(); \ No newline at end of file diff --git a/.snippets/code/web3-contract-local/increment.js b/.snippets/code/web3-contract-local/increment.js index 637021934..4aaf7a72e 100644 --- a/.snippets/code/web3-contract-local/increment.js +++ b/.snippets/code/web3-contract-local/increment.js @@ -1,36 +1,48 @@ +// 1. Import Web3js and the contract abi + const Web3 = require('web3'); const { abi } = require('./compile'); +// 2. Add the Web3 provider logic here: const providerRPC = { development: 'http://localhost:9944', moonbase: 'https://rpc.api.moonbase.moonbeam.network', }; -const web3 = new Web3(providerRPC.development); //Change to correct network +const web3 = new Web3(providerRPC.moonbase); //Change to correct network -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +// 3. Create variables +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; const _value = 3; +// 4. Create contract instance const incrementer = new web3.eth.Contract(abi, contractAddress); + +// 5. Build increment tx const incrementTx = incrementer.methods.increment(_value); + +// 6. Create increment function const increment = async () => { console.log( `Calling the increment by ${_value} function in contract at address: ${contractAddress}` ); + // 7. Prepare and Sign Tx with PK const createTransaction = await web3.eth.accounts.signTransaction( { to: contractAddress, data: incrementTx.encodeABI(), gas: await incrementTx.estimateGas(), }, - account_from.privateKey + accountFrom.privateKey ); + // 8. Send Tx and Wait for Receipt const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction); console.log(`Tx successful with hash: ${createReceipt.transactionHash}`); }; +// 9. Call increment function increment(); \ No newline at end of file diff --git a/.snippets/code/web3-contract-local/reset.js b/.snippets/code/web3-contract-local/reset.js index 807c2eae4..f898d593f 100644 --- a/.snippets/code/web3-contract-local/reset.js +++ b/.snippets/code/web3-contract-local/reset.js @@ -1,34 +1,44 @@ +// 1. Import Web3js and the contract abi const Web3 = require('web3'); const { abi } = require('./compile'); +// 2. Add the Web3 provider logic here: const providerRPC = { development: 'http://localhost:9944', moonbase: 'https://rpc.api.moonbase.moonbeam.network', }; -const web3 = new Web3(providerRPC.development); // Change to correct network +const web3 = new Web3(providerRPC.moonbase); // Change to correct network -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +// 3. Create variables +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; +// 4. Create contract instance const incrementer = new web3.eth.Contract(abi, contractAddress); + +// 5. Build reset tx const resetTx = incrementer.methods.reset(); +// 6. Create reset function const reset = async () => { console.log(`Calling the reset function in contract at address: ${contractAddress}`); + // 7. Prepare and sign tx with PK const createTransaction = await web3.eth.accounts.signTransaction( { to: contractAddress, data: resetTx.encodeABI(), gas: await resetTx.estimateGas(), }, - account_from.privateKey + accountFrom.privateKey ); + // 8. Send tx and wait for receipt const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction); console.log(`Tx successful with hash: ${createReceipt.transactionHash}`); }; +// 9. Call reset function reset(); \ No newline at end of file diff --git a/.snippets/code/web3-tx-local/balances.js b/.snippets/code/web3-tx-local/balances.js index f7d26e6a8..6d15faaa5 100644 --- a/.snippets/code/web3-tx-local/balances.js +++ b/.snippets/code/web3-tx-local/balances.js @@ -1,20 +1,25 @@ const Web3 = require('web3'); +// 1. Add the Web3 provider logic here: const providerRPC = { development: 'http://localhost:9944', moonbase: 'https://rpc.api.moonbase.moonbeam.network', }; -const web3 = new Web3(providerRPC.development); // Change to correct network +const web3 = new Web3(providerRPC.moonbase); // Change to correct network -const addressFrom = 'ADDRESS-FROM-HERE'; -const addressTo = 'ADDRESS-TO-HERE'; +// 2. Create address variables +const addressFrom = 'INSERT_FROM_ADDRESS'; +const addressTo = 'INSERT_TO_ADDRESS'; +// 3. Create balances function const balances = async () => { + // 4. Fetch balance info const balanceFrom = web3.utils.fromWei(await web3.eth.getBalance(addressFrom), 'ether'); const balanceTo = web3.utils.fromWei(await web3.eth.getBalance(addressTo), 'ether'); - console.log(`The balance of ${addressFrom} is: ${balanceFrom} ETH`); - console.log(`The balance of ${addressTo} is: ${balanceTo} ETH`); + console.log(`The balance of ${addressFrom} is: ${balanceFrom} DEV`); + console.log(`The balance of ${addressTo} is: ${balanceTo} DEV`); }; +// 5. Call balances function balances(); \ No newline at end of file diff --git a/.snippets/code/web3-tx-local/transaction.js b/.snippets/code/web3-tx-local/transaction.js index 906893a25..ce2b5242a 100644 --- a/.snippets/code/web3-tx-local/transaction.js +++ b/.snippets/code/web3-tx-local/transaction.js @@ -1,31 +1,37 @@ const Web3 = require('web3'); +// 1. Add the Web3 provider logic here: const providerRPC = { development: 'http://localhost:9944', moonbase: 'https://rpc.api.moonbase.moonbeam.network', }; -const web3 = new Web3(providerRPC.development); // Change to correct network +const web3 = new Web3(providerRPC.moonbase); // Change to correct network -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', - address: 'PUBLIC-ADDRESS-OF-PK-HERE', +// 2. Create account variables +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', + address: 'INSERT_PUBLIC_ADDRESS_OF_PK', }; -const addressTo = 'ADDRESS-TO-HERE'; +const addressTo = 'INSERT_TO_ADDRESS'; +// 3. Create send function const send = async () => { - console.log(`Attempting to send transaction from ${account_from.address} to ${addressTo}`); + console.log(`Attempting to send transaction from ${accountFrom.address} to ${addressTo}`); + // 4. Prepare and sign tx with PK const createTransaction = await web3.eth.accounts.signTransaction( { gas: 21000, to: addressTo, value: web3.utils.toWei('1', 'ether'), }, - account_from.privateKey + accountFrom.privateKey ); + // 5. Send tx and wait for receipt const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction); console.log(`Transaction successful with hash: ${createReceipt.transactionHash}`); }; +// 6. Call send function send(); \ No newline at end of file diff --git a/.snippets/code/web3py-contract/deploy.py b/.snippets/code/web3py-contract/deploy.py index fb6e144bb..924c74904 100644 --- a/.snippets/code/web3py-contract/deploy.py +++ b/.snippets/code/web3py-contract/deploy.py @@ -11,8 +11,8 @@ # 3. Create address variable account_from = { - 'private_key': 'YOUR_PRIVATE_KEY_HERE', - 'address': 'PUBLIC_ADDRESS_OF_PK_HERE', + 'private_key': 'INSERT_YOUR_PRIVATE_KEY', + 'address': 'INSERT_PUBLIC_ADDRESS_OF_PK', } print(f'Attempting to deploy from account: { account_from["address"] }') diff --git a/.snippets/code/web3py-contract/get.py b/.snippets/code/web3py-contract/get.py index 4c7079304..dfadee0e3 100644 --- a/.snippets/code/web3py-contract/get.py +++ b/.snippets/code/web3py-contract/get.py @@ -10,7 +10,7 @@ web3 = Web3(Web3.HTTPProvider(provider_rpc['development'])) # Change to correct network # 3. Create address variable -contract_address = 'CONTRACT_ADDRESS_HERE' +contract_address = 'INSERT_CONTRACT_ADDRESS' print(f'Making a call to contract at address: { contract_address }') diff --git a/.snippets/code/web3py-contract/increment.py b/.snippets/code/web3py-contract/increment.py index 4205bf02b..c062c1d2c 100644 --- a/.snippets/code/web3py-contract/increment.py +++ b/.snippets/code/web3py-contract/increment.py @@ -11,10 +11,10 @@ # 3. Create variables account_from = { - 'private_key': 'YOUR_PRIVATE_KEY_HERE', - 'address': 'PUBLIC_ADDRESS_OF_PK_HERE', + 'private_key': 'INSERT_YOUR_PRIVATE_KEY', + 'address': 'INSERT_PUBLIC_ADDRESS_OF_PK', } -contract_address = 'CONTRACT_ADDRESS_HERE' +contract_address = 'INSERT_CONTRACT_ADDRESS' value = 3 print( diff --git a/.snippets/code/web3py-contract/reset.py b/.snippets/code/web3py-contract/reset.py index d87712a16..9e62d97ab 100644 --- a/.snippets/code/web3py-contract/reset.py +++ b/.snippets/code/web3py-contract/reset.py @@ -11,10 +11,10 @@ # 3. Create variables account_from = { - 'private_key': 'YOUR_PRIVATE_KEY_HERE', - 'address': 'PUBLIC_ADDRESS_OF_PK_HERE', + 'private_key': 'INSERT_YOUR_PRIVATE_KEY', + 'address': 'INSERT_PUBLIC_ADDRESS_OF_PK', } -contract_address = 'CONTRACT_ADDRESS_HERE' +contract_address = 'INSERT_CONTRACT_ADDRESS' print(f'Calling the reset function in contract at address: { contract_address }') diff --git a/.snippets/code/web3py-tx/balances.py b/.snippets/code/web3py-tx/balances.py index e92ac6de3..cbb74dcdd 100644 --- a/.snippets/code/web3py-tx/balances.py +++ b/.snippets/code/web3py-tx/balances.py @@ -9,8 +9,8 @@ web3 = Web3(Web3.HTTPProvider(provider_rpc['development'])) # Change to correct network # 2. Create address variables -address_from = 'ADDRESS_FROM_HERE' -address_to = 'ADDRESS_TO_HERE' +address_from = 'INSERT_FROM_ADDRESS' +address_to = 'INSERT_TO_ADDRESS' # 3. Fetch balance data balance_from = web3.from_wei(web3.eth.getBalance(address_from), 'ether') diff --git a/.snippets/code/web3py-tx/transaction.py b/.snippets/code/web3py-tx/transaction.py index fcd7e1474..c40284a93 100644 --- a/.snippets/code/web3py-tx/transaction.py +++ b/.snippets/code/web3py-tx/transaction.py @@ -11,10 +11,10 @@ # 3. Create address variables account_from = { - 'private_key': 'YOUR_PRIVATE_KEY_HERE', - 'address': 'PUBLIC_ADDRESS_OF_PK_HERE', + 'private_key': 'INSERT_YOUR_PRIVATE_KEY', + 'address': 'INSERT_PUBLIC_ADDRESS_OF_PK', } -address_to = 'ADDRESS_TO_HERE' +address_to = 'INSERT_TO_ADDRESS' print( f'Attempting to send transaction from { account_from["address"] } to { address_to }' diff --git a/builders/build/eth-api/libraries/ethersjs.md b/builders/build/eth-api/libraries/ethersjs.md index 953bf9339..15f117175 100644 --- a/builders/build/eth-api/libraries/ethersjs.md +++ b/builders/build/eth-api/libraries/ethersjs.md @@ -7,7 +7,7 @@ description: Follow this tutorial to learn how to use the Ethereum Ethers.js Lib ## Introduction {: #introduction } -The [Ethers.js](https://docs.ethers.io/){target=_blank} library provides a set of tools to interact with Ethereum Nodes with JavaScript, similar to Web3.js. Moonbeam has an Ethereum-like API available that is fully compatible with Ethereum-style JSON RPC invocations. Therefore, developers can leverage this compatibility and use the Ethers.js library to interact with a Moonbeam node as if they were doing so on Ethereum. You can read more about Ethers.js on this [blog post](https://medium.com/l4-media/announcing-ethers-js-a-web3-alternative-6f134fdd06f3){target=_blank}. +The [Ethers.js](https://docs.ethers.org/){target=_blank} library provides a set of tools to interact with Ethereum Nodes with JavaScript, similar to Web3.js. Moonbeam has an Ethereum-like API available that is fully compatible with Ethereum-style JSON RPC invocations. Therefore, developers can leverage this compatibility and use the Ethers.js library to interact with a Moonbeam node as if they were doing so on Ethereum. For more information on Ethers.js, check their [documentation site](https://docs.ethers.org/v6/){target=_blank}. In this guide, you'll learn how to use the Ethers.js library to send a transaction and deploy a contract on Moonbase Alpha. This guide can be adapted for [Moonbeam](/builders/get-started/networks/moonbeam/){target=_blank}, [Moonriver](/builders/get-started/networks/moonriver/){target=_blank}, or a [Moonbeam development node](/builders/get-started/networks/moonbeam-dev/){target=_blank}. @@ -23,23 +23,31 @@ For the examples in this guide, you will need to have the following: !!! note --8<-- 'text/common/assumes-mac-or-ubuntu-env.md' -## Create a JavaScript Project {: #create-a-javascript-project } +## Installing Ethers.js {: #install-ethersjs } -To get started, you can create a directory to store all of the files you'll be creating throughout this guide: +To get started, you'll need to start a basic JavaScript project. First, create a directory to store all of the files you'll be creating throughout this guide and initialize the project with the following command: ```bash -mkdir ethers-examples && cd ethers-examples +mkdir ethers-examples && cd ethers-examples && npm init --y ``` For this guide, you'll need to install the Ethers.js library and the Solidity compiler. To install both NPM packages, you can run the following command: -```bash -npm install ethers solc@0.8.0 -``` +=== "npm" + + ```bash + npm install ethers solc@0.8.0 + ``` + +=== "yarn" + + ```bash + yarn add ethers solc@0.8.0 + ``` ## Setting up the Ethers Provider {: #setting-up-the-ethers-provider } -Throughout this guide, you'll be creating a bunch of scripts that provide different functionality such as sending a transaction, deploying a contract, and interacting with a deployed contract. In most of these scripts you'll need to create an [Ethers provider](https://docs.ethers.io/v6/api/providers/){target=_blank} to interact with the network. +Throughout this guide, you'll be creating a bunch of scripts that provide different functionality such as sending a transaction, deploying a contract, and interacting with a deployed contract. In most of these scripts you'll need to create an [Ethers provider](https://docs.ethers.org/v6/api/providers/){target=_blank} to interact with the network. --8<-- 'text/common/endpoint-setup.md' @@ -145,6 +153,8 @@ To create a provider, you can take the following steps: ); ``` +Save this code snippet as you'll need it for the scripts that are used in the following sections. + ## Send a Transaction {: #send-a-transaction } During this section, you'll be creating a couple of scripts. The first one will be to check the balances of your accounts before trying to send a transaction. The second script will actually send the transaction. @@ -172,8 +182,8 @@ Next, you will create the script for this file and complete the following steps: // {...} // 2. Create address variables -const addressFrom = 'ADDRESS-FROM-HERE'; -const addressTo = 'ADDRESS-TO-HERE'; +const addressFrom = 'INSERT_FROM_ADDRESS'; +const addressTo = 'INSERT_TO_ADDRESS'; // 3. Create balances function const balances = async () => { @@ -181,15 +191,19 @@ const balances = async () => { const balanceFrom = ethers.formatEther(await provider.getBalance(addressFrom)); const balanceTo = ethers.formatEther(await provider.getBalance(addressTo)); - console.log(`The balance of ${addressFrom} is: ${balanceFrom} ETH`); - console.log(`The balance of ${addressTo} is: ${balanceTo} ETH`); + console.log(`The balance of ${addressFrom} is: ${balanceFrom} DEV`); + console.log(`The balance of ${addressTo} is: ${balanceTo} DEV`); }; // 5. Call the balances function balances(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/ethers-tx-local/balances.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/ethers-js-tx/balances.js' + ``` To run the script and fetch the account balances, you can run the following command: @@ -197,7 +211,7 @@ To run the script and fetch the account balances, you can run the following comm node balances.js ``` -If successful, the balances for the origin and receiving address will be displayed in your terminal in ETH. +If successful, the balances for the origin and receiving address will be displayed in your terminal in DEV. ### Send Transaction Script {: #send-transaction-script } @@ -222,13 +236,13 @@ Next, you will create the script for this file and complete the following steps: // {...} // 2. Create account variables -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const addressTo = 'ADDRESS-TO-HERE'; +const addressTo = 'INSERT_TO_ADDRESS'; // 3. Create wallet -let wallet = new ethers.Wallet(account_from.privateKey, provider); +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); // 4. Create send function const send = async () => { @@ -250,7 +264,11 @@ const send = async () => { send(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/ethers-tx-local/transaction.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/ethers-js-tx/transaction.js' + ``` To run the script, you can run the following command in your terminal: @@ -285,8 +303,8 @@ Next, you will create the script for this file and complete the following steps: 1. Import the contract file from `compile.js` 2. [Set up the Ethers provider](#setting-up-the-ethers-provider) 3. Define the `privateKey` for the origin account. The private key is required to create a wallet instance. **Note: This is for example purposes only. Never store your private keys in a JavaScript file** -4. Save the `bytecode` and `abi` for the compiled contract -5. Create a wallet using the `privateKey` and `provider` from the previous steps. The wallet instance is used to sign transactions +4. Create a wallet using the `privateKey` and `provider` from the previous steps. The wallet instance is used to sign transactions +5. Load the contract `bytecode` and `abi` for the compiled contract 6. Create a contract instance with signer using the `ethers.ContractFactory` function, providing the `abi`, `bytecode`, and `wallet` as parameters 7. Create the asynchronous `deploy` function that will be used to deploy the contract 8. Within the `deploy` function, use the `incrementer` contract instance to call `deploy` and pass in the initial value. For this example, you can set the initial value to `5`. This will send the transaction for contract deployment. To wait for a transaction receipt you can use the `deployed` method of the contract deployment transaction @@ -300,17 +318,17 @@ const contractFile = require('./compile'); // {...} // 3. Create account variables -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -// 4. Save the bytecode and ABI +// 4. Create wallet +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); + +// 5. Load contract information const bytecode = contractFile.evm.bytecode.object; const abi = contractFile.abi; -// 5. Create wallet -let wallet = new ethers.Wallet(account_from.privateKey, provider); - // 6. Create contract instance with signer const incrementer = new ethers.ContractFactory(abi, bytecode, wallet); @@ -329,7 +347,11 @@ const deploy = async () => { deploy(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/ethers-contract-local/deploy.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/ethers-js-contract/deploy.js' + ``` To run the script, you can enter the following command into your terminal: @@ -341,7 +363,6 @@ If successful, the contract's address will be displayed in the terminal. ![Deploy Contract Etherjs](/images/builders/build/eth-api/libraries/ethers/ethers-2.png) - ### Read Contract Data (Call Methods) {: #read-contract-data } Call methods are the type of interaction that don't modify the contract's storage (change variables), meaning no transaction needs to be sent. They simply read various storage variables of the deployed contract. @@ -370,7 +391,7 @@ const { abi } = require('./compile'); // {...} // 3. Contract address variable -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; // 4. Create contract instance const incrementer = new ethers.Contract(contractAddress, abi, provider); @@ -389,7 +410,11 @@ const get = async () => { get(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/ethers-contract-local/get.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/ethers-js-contract/get.js' + ``` To run the script, you can enter the following command in your terminal: @@ -426,14 +451,14 @@ const { abi } = require('./compile'); // {...} // 3. Create variables -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; const _value = 3; // 4. Create wallet -let wallet = new ethers.Wallet(account_from.privateKey, provider); +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); // 5. Create contract instance with signer const incrementer = new ethers.Contract(contractAddress, abi, wallet); @@ -455,7 +480,11 @@ const increment = async () => { increment(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/ethers-contract-local/increment.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/ethers-js-contract/increment.js' + ``` To run the script, you can enter the following command in your terminal: @@ -486,13 +515,13 @@ const { abi } = require('./compile'); // {...} // 3. Create variables -const account_from = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', +const accountFrom = { + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; // 4. Create wallet -let wallet = new ethers.Wallet(account_from.privateKey, provider); +let wallet = new ethers.Wallet(accountFrom.privateKey, provider); // 5. Create contract instance with signer const incrementer = new ethers.Contract(contractAddress, abi, wallet); @@ -512,7 +541,11 @@ const reset = async () => { reset(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/ethers-contract-local/reset.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/ethers-js-contract/reset.js' + ``` To run the script, you can enter the following command in your terminal: diff --git a/builders/build/eth-api/libraries/web3js.md b/builders/build/eth-api/libraries/web3js.md index 8a738f6d0..cd697b136 100644 --- a/builders/build/eth-api/libraries/web3js.md +++ b/builders/build/eth-api/libraries/web3js.md @@ -23,19 +23,27 @@ For the examples in this guide, you will need to have the following: !!! note --8<-- 'text/common/assumes-mac-or-ubuntu-env.md' -## Create a JavaScript Project {: #create-a-javascript-project } +## Installing Web3.js {: #install-web3js } -To get started, you can create a directory to store all of the files you'll be creating throughout this guide: +To get started, you'll need to start a basic JavaScript project. First, create a directory to store all of the files you'll be creating throughout this guide and initialize the project with the following command: ```bash -mkdir web3-examples && cd web3-examples +mkdir web3-examples && cd web3-examples && npm init --y ``` For this guide, you'll need to install the Web3.js library and the Solidity compiler. To install both NPM packages, you can run the following command: -```bash -npm install web3 solc@0.8.0 -``` +=== "npm" + + ```bash + npm install web3 solc@0.8.0 + ``` + +=== "yarn" + + ```bash + yarn add web3 solc@0.8.0 + ``` ## Setup Web3.js with Moonbeam {: #setup-web3-with-moonbeam } @@ -80,6 +88,8 @@ The simplest way to get started with each of the networks is as follows: const web3 = new Web3('{{ networks.development.rpc_url }}'); ``` +Save this code snippet as you'll need it for the scripts that are used in the following sections. + ## Send a Transaction {: #send-a-transaction } During this section, you'll be creating a couple of scripts. The first one will be to check the balances of your accounts before trying to send a transaction. The second script will actually send the transaction. @@ -99,7 +109,7 @@ Next, you will create the script for this file and complete the following steps: 1. [Set up the Web3 provider](#setup-web3-with-moonbeam) 2. Define the `addressFrom` and `addressTo` variables 3. Create the asynchronous `balances` function which wraps the `web3.eth.getBalance` method -4. Use the `web3.eth.getBalance` function to fetch the balances for the `addressFrom` and `addressTo` addresses. You can also leverage the `web3.utils.fromWei` function to transform the balance into a more readable number in ETH +4. Use the `web3.eth.getBalance` function to fetch the balances for the `addressFrom` and `addressTo` addresses. You can also leverage the `web3.utils.fromWei` function to transform the balance into a more readable number in DEV 5. Lastly, run the `balances` function ```js @@ -107,8 +117,8 @@ Next, you will create the script for this file and complete the following steps: // {...} // 2. Create address variables -const addressFrom = 'ADDRESS-FROM-HERE'; -const addressTo = 'ADDRESS-TO-HERE'; +const addressFrom = 'INSERT_FROM_ADDRESS'; +const addressTo = 'INSERT_TO_ADDRESS'; // 3. Create balances function const balances = async () => { @@ -116,15 +126,19 @@ const balances = async () => { const balanceFrom = web3.utils.fromWei(await web3.eth.getBalance(addressFrom), 'ether'); const balanceTo = web3.utils.fromWei(await web3.eth.getBalance(addressTo), 'ether'); - console.log(`The balance of ${addressFrom} is: ${balanceFrom} ETH`); - console.log(`The balance of ${addressTo} is: ${balanceTo} ETH`); + console.log(`The balance of ${addressFrom} is: ${balanceFrom} DEV`); + console.log(`The balance of ${addressTo} is: ${balanceTo} DEV`); }; // 5. Call balances function balances(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/web3-tx-local/balances.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/web3-tx-local/balances.js' + ``` To run the script and fetch the account balances, you can run the following command: @@ -132,7 +146,7 @@ To run the script and fetch the account balances, you can run the following comm node balances.js ``` -If successful, the balances for the origin and receiving address will be displayed in your terminal in ETH. +If successful, the balances for the origin and receiving address will be displayed in your terminal in DEV. ### Send Transaction Script {: #send-transaction-script } @@ -157,10 +171,10 @@ Next, you will create the script for this file and complete the following steps: // 2. Create account variables const accountFrom = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', - address: 'PUBLIC-ADDRESS-OF-PK-HERE', + privateKey: 'INSERT_YOUR_PRIVATE_KEY', + address: 'INSERT_PUBLIC_ADDRESS_OF_PK', }; -const addressTo = 'ADDRESS-TO-HERE'; // Change addressTo +const addressTo = 'INSERT_TO_ADDRESS'; // Change addressTo // 3. Create send function const send = async () => { @@ -185,7 +199,11 @@ const send = async () => { send(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/web3-tx-local/transaction.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/web3-tx-local/transaction.js' + ``` To run the script, you can run the following command in your terminal: @@ -237,8 +255,8 @@ const contractFile = require('./compile'); // 3. Create address variables const accountFrom = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', - address: 'PUBLIC-ADDRESS-OF-PK-HERE', + privateKey: 'INSERT_YOUR_PRIVATE_KEY', + address: 'INSERT_PUBLIC_ADDRESS_OF_PK', }; // 4. Get the bytecode and API @@ -276,7 +294,11 @@ const deploy = async () => { deploy(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/web3-contract-local/deploy.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/web3-contract-local/deploy.js' + ``` To run the script, you can enter the following command into your terminal: @@ -316,7 +338,7 @@ const { abi } = require('./compile'); // {...} // 3. Create address variables -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; // 4. Create contract instance const incrementer = new web3.eth.Contract(abi, contractAddress); @@ -335,7 +357,11 @@ const get = async () => { get(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/web3-contract-local/get.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/web3-contract-local/get.js' + ``` To run the script, you can enter the following command in your terminal: @@ -374,9 +400,9 @@ const { abi } = require('./compile'); // 3. Create variables const accountFrom = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; const _value = 3; // 4. Create contract instance @@ -391,7 +417,7 @@ const increment = async () => { `Calling the increment by ${_value} function in contract at address: ${contractAddress}` ); - // Sign Tx with PK + // 7. Prepare and Sign Tx with PK const createTransaction = await web3.eth.accounts.signTransaction( { to: contractAddress, @@ -401,7 +427,7 @@ const increment = async () => { accountFrom.privateKey ); - // Send Tx and Wait for Receipt + // 8. Send Tx and Wait for Receipt const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction); console.log(`Tx successful with hash: ${createReceipt.transactionHash}`); }; @@ -410,7 +436,11 @@ const increment = async () => { increment(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/web3-contract-local/increment.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/web3-contract-local/increment.js' + ``` To run the script, you can enter the following command in your terminal: @@ -443,9 +473,9 @@ const { abi } = require('./compile'); // 3. Create variables const accountFrom = { - privateKey: 'YOUR-PRIVATE-KEY-HERE', + privateKey: 'INSERT_YOUR_PRIVATE_KEY', }; -const contractAddress = 'CONTRACT-ADDRESS-HERE'; +const contractAddress = 'INSERT_CONTRACT_ADDRESS'; // 4. Create Contract Instance const incrementer = new web3.eth.Contract(abi, contractAddress); @@ -476,7 +506,11 @@ const reset = async () => { reset(); ``` -You can view the [complete script on GitHub](https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-docs/master/.snippets/code/web3-contract-local/reset.js){target=_blank}. +??? code "View the complete script" + + ```js + --8<-- 'code/web3-contract-local/reset.js' + ``` To run the script, you can enter the following command in your terminal: diff --git a/builders/get-started/eth-compare/consensus-finality.md b/builders/get-started/eth-compare/consensus-finality.md index 28eac0821..f1ecf59b8 100644 --- a/builders/get-started/eth-compare/consensus-finality.md +++ b/builders/get-started/eth-compare/consensus-finality.md @@ -83,7 +83,7 @@ The snippets below follow the strategy outlined in the [previous section](#strat --8<-- 'code/vs-ethereum/consensus-finality/web3.py' ``` -You can modify these scripts to use `moon_isBlockFinalized` and `moon_isTxFinalized`. To do this, you can make custom calls to the Substrate JSON-RPC using the `send` method of both [Web3.js](https://web3js.readthedocs.io/){target=_blank} and [Ethers.js](https://docs.ethers.io/){target=_blank}. Custom RPC requests are also possible using [Web3.py](https://web3py.readthedocs.io/){target=_blank} with the `make_request` method. You'll need to pass in the method name and the parameters to the custom request, which you can find on the [Moonbeam Custom API](/builders/build/moonbeam-custom-api/){target=_blank} page. +You can modify these scripts to use `moon_isBlockFinalized` and `moon_isTxFinalized`. To do this, you can make custom calls to the Substrate JSON-RPC using the `send` method of both [Web3.js](https://web3js.readthedocs.io/){target=_blank} and [Ethers.js](https://docs.ethers.org/){target=_blank}. Custom RPC requests are also possible using [Web3.py](https://web3py.readthedocs.io/){target=_blank} with the `make_request` method. You'll need to pass in the method name and the parameters to the custom request, which you can find on the [Moonbeam Custom API](/builders/build/moonbeam-custom-api/){target=_blank} page. === "Ethers.js" diff --git a/builders/integrations/wallets/walletconnect.md b/builders/integrations/wallets/walletconnect.md index cb36471f8..e1e8b4889 100644 --- a/builders/integrations/wallets/walletconnect.md +++ b/builders/integrations/wallets/walletconnect.md @@ -339,7 +339,7 @@ You can test this logic out by refreshing the page after establishing a connecti ## Add Account Balance {: #add-account-balance } -Depending on your needs, you might want to show the connected account's balance for the connected network. To do so, you can use [Ethers](https://docs.ethers.io/){target=_blank} to create a provider which can then be used to fetch the balance of the connected account. +Depending on your needs, you might want to show the connected account's balance for the connected network. To do so, you can use [Ethers](https://docs.ethers.org/){target=_blank} to create a provider which can then be used to fetch the balance of the connected account. You can start by adding another state variable for `balance`. diff --git a/builders/interoperability/xcm/xcm-sdk/v0/xcm-sdk.md b/builders/interoperability/xcm/xcm-sdk/v0/xcm-sdk.md index 7e5f79e2f..5e0e2a85e 100644 --- a/builders/interoperability/xcm/xcm-sdk/v0/xcm-sdk.md +++ b/builders/interoperability/xcm/xcm-sdk/v0/xcm-sdk.md @@ -35,7 +35,7 @@ To install the XCM SDK and XCM config packages, you can run the following comman npm install @moonbeam-network/xcm-sdk @moonbeam-network/xcm-config ``` -You need to have peer dependencies, like [Ethers.js](https://docs.ethers.io/){target=_blank} and the [Polkadot.js API](https://polkadot.js.org/docs/api/){target=_blank} installed. +You need to have peer dependencies, like [Ethers.js](https://docs.ethers.org/){target=_blank} and the [Polkadot.js API](https://polkadot.js.org/docs/api/){target=_blank} installed. You can install them by running the following command: @@ -48,7 +48,7 @@ npm i @polkadot/api-augment @polkadot/types @polkadot/util @polkadot/util-crypto ### Creating Signers {: creating-signers } -When interacting with the `deposit` and `withdraw` functions of the XCM SDK, you'll need to provide an [Ethers.js](https://docs.ethers.io/){target=_blank} and [Polkadot.js](https://polkadot.js.org/docs/api/){target=_blank} signer, which will be used to sign and send the transactions. The Ethers signer is used to sign transactions on Moonbeam, and the Polkadot signer will be used to sign transactions on the origin chain you're depositing assets from. +When interacting with the `deposit` and `withdraw` functions of the XCM SDK, you'll need to provide an [Ethers.js](https://docs.ethers.org/){target=_blank} and [Polkadot.js](https://polkadot.js.org/docs/api/){target=_blank} signer, which will be used to sign and send the transactions. The Ethers signer is used to sign transactions on Moonbeam, and the Polkadot signer will be used to sign transactions on the origin chain you're depositing assets from. You can pass, for example, a [MetaMask signer into Ethers](https://docs.ethers.org/v6/getting-started/#starting-connecting){target=_blank} or another compatible wallet. Similarly with Polkadot, you can [pass a compatible wallet to the signer using the `@polkadot/extension-dapp` library](https://polkadot.js.org/docs/extension/){target=_blank}. diff --git a/builders/pallets-precompiles/precompiles/call-permit.md b/builders/pallets-precompiles/precompiles/call-permit.md index 8b13ec0c3..132a30995 100644 --- a/builders/pallets-precompiles/precompiles/call-permit.md +++ b/builders/pallets-precompiles/precompiles/call-permit.md @@ -162,7 +162,7 @@ Regardless of which method you choose to generate the signature, the following s 2. A JSON structure of the data the user needs to sign will be assembled for the call permit and include all of the types for the `dispatch` arguments and the nonce. This will result in the `CallPermit` type and will be saved as the `primaryType` 3. The domain separator will be created using `"Call Permit Precompile"` exactly for the name, the version of your DApp or platform, the chain ID of the network the signature is to be used on, and the address of the contract that will verify the signature 4. All of the assembled data, the `types`, `domain`, `primaryType` and `message`, will be signed using MetaMask (either in the browser or through the MetaMask's JavaScript signing library) -5. The signature will be returned and you can use [Ethers.js](https://docs.ethers.io/){target=_blank} [`Signature.from` method](https://docs.ethers.org/v6/api/crypto/#Signature_from){target=_blank} to return the `v`, `r`, and `s` values of the signature +5. The signature will be returned and you can use [Ethers.js](https://docs.ethers.org/){target=_blank} [`Signature.from` method](https://docs.ethers.org/v6/api/crypto/#Signature_from){target=_blank} to return the `v`, `r`, and `s` values of the signature ### The Call Permit Arguments {: #call-permit-arguments } @@ -229,7 +229,7 @@ You should now have a file where you can create the script to get the signature "type": "module" ``` -Next, you can install the MetaMask signing library and [Ethers.js](https://docs.ethers.io/){target=_blank}: +Next, you can install the MetaMask signing library and [Ethers.js](https://docs.ethers.org/){target=_blank}: ```bash npm i @metamask/eth-sig-util ethers diff --git a/tutorials/integrations/nft-subsquid.md b/tutorials/integrations/nft-subsquid.md index 9a0d111ed..b7eb3195c 100644 --- a/tutorials/integrations/nft-subsquid.md +++ b/tutorials/integrations/nft-subsquid.md @@ -103,7 +103,7 @@ The (re)generated entity classes can then be browsed at `src/model/generated`. Subsquid maintains [tools](https://docs.subsquid.io/substrate-indexing/squid-substrate-typegen/){target=_blank} for automated generation of TypeScript classes for handling Substrate data sources (events, extrinsics, storage items). Possible runtime upgrades are automatically detected and accounted for. -Similar functionality is available for EVM indexing through the [`squid-evm-typegen`](https://docs.subsquid.io/evm-indexing/squid-evm-typegen/){target=_blank} tool. It generates TypeScript modules for handling EVM logs and transactions based on a [JSON ABI](https://docs.ethers.io/v5/api/utils/abi/){target=_blank} of the contract. +Similar functionality is available for EVM indexing through the [`squid-evm-typegen`](https://docs.subsquid.io/evm-indexing/squid-evm-typegen/){target=_blank} tool. It generates TypeScript modules for handling EVM logs and transactions based on a [JSON ABI](https://docs.ethers.org/v5/api/utils/abi/){target=_blank} of the contract. For our squid we will need such a module for the [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=_blank}-compliant part of the contracts' interfaces. Once again, the template repository already includes it, but it is still important to explain what needs to be done in case one wants to index a different type of contract.