Skip to content

Instantly share code, notes, and snippets.

View cds-amal's full-sized avatar
🏠
Working from home

cds-amal cds-amal

🏠
Working from home
  • Flushing USA
View GitHub Profile
@cds-amal
cds-amal / .prettierrc.json
Created March 2, 2024 14:19
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.24+commit.e11b9ed9.js&optimize=false&runs=200&gist=
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false

Explain the solidity memory anotation

The memory keyword in Solidity is used to denote a temporary storage location within the Ethereum Virtual Machine (EVM) for variables that are not meant to persist between function calls. This is analogous to RAM in a computer, where data stored in memory is temporary and gets erased after the execution of the function it is used in. The EVM has three primary storage locations for data: storage, memory, and stack.

  • Storage: This is where all the contract's state variables reside. It is persistent across function calls and is more expensive to use due to the cost of writing to the blockchain.
  • Memory: This is used for temporary data. It is cheaper to use than storage because it is erased between function calls, making it suitable for intermediate calculations or temporary data structures.
  • Stack: This is used for small local variables and is almost free to use, but it has a limited capacity.

When you declare a variable with the memory keyword,

@cds-amal
cds-amal / Tvest.sol
Created October 19, 2023 14:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.21+commit.d9974bed.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
contract Empty {
// hi, I'm bar. i was audited
function foo() public {}
function bar() public {}
}
/*
@cds-amal
cds-amal / .prettierrc.json
Created October 12, 2023 02:21
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.21+commit.d9974bed.js&optimize=false&runs=200&gist=
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
@cds-amal
cds-amal / String.yul
Created July 18, 2023 06:20
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
object "YulString" {
code {
// Deploy the contract
datacopy(0, dataoffset("runtime"), datasize("runtime"))
return(0, datasize("runtime"))
}
object "runtime" {
code {
// don't accept value
@cds-amal
cds-amal / Order.sol
Created July 8, 2023 15:47
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.20+commit.a1b79de6.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract A {
function foo() public pure returns (uint) { return bar(); }
function bar() public virtual pure returns (uint) { return 1; }
}
contract B is A { }
@cds-amal
cds-amal / preprocessor_fun.h
Created November 22, 2022 09:15 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,

I set up test project based on the metacoin-box (truffle unbox metacoin mc) with two test folders

  • test - has js tests
  • test-solidity - has solidity tests
Test layout

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›

reprod test-from truffle unbox metacoin rm contracts/Migrations.sol rm migrations/*.js cat << EOF > migrations/1_deploy_it.js const ConvertLib = artifacts.require("ConvertLib"); const MetaCoin = artifacts.require("MetaCoin");

module.exports = async function(deployer, network, accounts) { const from = accounts[1];

@cds-amal
cds-amal / foo.md
Last active February 19, 2022 21:39

verdaccio

  1. install
    npm -g install verdaccio
  2. configure
    cat << EOF > config.yml
    listen: