Skip to content
Merged
38 changes: 0 additions & 38 deletions .snippets/code/ethers-contract-local/reset.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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();
// Call the deploy function
deploy();
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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();
// Call get function
get();
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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();
// Call the reset function
increment();
51 changes: 51 additions & 0 deletions .snippets/code/ethers-js-contract/reset.js
Original file line number Diff line number Diff line change
@@ -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();
41 changes: 41 additions & 0 deletions .snippets/code/ethers-js-tx/balances.js
Original file line number Diff line number Diff line change
@@ -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();
49 changes: 49 additions & 0 deletions .snippets/code/ethers-js-tx/transaction.js
Original file line number Diff line number Diff line change
@@ -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();
32 changes: 0 additions & 32 deletions .snippets/code/ethers-tx-local/balances.js

This file was deleted.

Loading