This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.23; | |
contract TransactionInfo { | |
// State variable to store contract balance | |
uint256 public contractBalance; | |
// Variables to store transaction details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract TransactionInfo { | |
address public owner; | |
uint256 public contractBalance; | |
constructor() { | |
// Set the owner to the account that deploys the contract | |
owner = msg.sender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.17; | |
contract Parent { | |
function foo() public pure virtual returns (string memory) { | |
return "A"; | |
} | |
function bar() public pure virtual returns (string memory) { | |
return "B"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.12; | |
contract SafeMath { | |
// uint8 public number = 255; | |
uint8 public number = 2**8 - 1; | |
function increment() public { | |
unchecked { | |
number++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.17; | |
contract Visibility { | |
uint256 private x = 0; | |
uint256 internal y = 1; | |
uint256 public z = 2; | |
// Public | |
// Accesed from any smart contract, function inside |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.17; | |
contract VariablesAndDataTypes { | |
// State Variables | |
int256 public oneIng = 1; | |
uint256 public oneUint = 1; | |
// Local Variable | |
function getValue() public pure returns(uint256) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers') | |
const { toChecksumAddress } = require('ethereum-checksum-address') | |
require('dotenv').config() | |
const main = async () => { | |
// Connect to an EVM network | |
const provider = new ethers.providers.JsonRpcProvider(`https://rpc.ankr.com/bsc`) | |
// Create a Factory contract abi | |
const IPair = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers') | |
const { toChecksumAddress } = require('ethereum-checksum-address') | |
require('dotenv').config() | |
const main = async () => { | |
// Connect to an EVM network | |
const provider = new ethers.providers.JsonRpcProvider(`https://polygon-mainnet.g.alchemy.com/v2/${process.env.RPC_KEY}`) | |
// Create a wallet | |
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY) | |
// Get a signer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') | |
require('dotenv').config() | |
const main = async () => { | |
// Connect to a EVM blockchain | |
const web3 = new Web3(Web3.givenProvider || process.env.INFURA_URL) | |
// Convert from a decimal number to a wei number | |
let amt = web3.utils.toWei('0.1', 'ether') | |
console.log('Convert from a decimal number to a wei number', amt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers') | |
const { toChecksumAddress } = require('ethereum-checksum-address') | |
require('dotenv').config() | |
const main = async () => { | |
// Connect to an EVM network | |
const provider = new ethers.providers.JsonRpcProvider(`https://polygon-mainnet.g.alchemy.com/v2/${process.env.RPC_KEY}`) | |
// Create a wallet | |
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY) | |
// Get a signer |
NewerOlder