설치
brew tap ethereum/solc
brew install solidity
solc 특정 버전 설치
solc-select install 0.7.6
solc 특정 버전 사용 (사용 전 설치되어야 한다)
solc-select use 0.7.6
brew tap ethereum/solc
brew install solidity
solc-select install 0.7.6
solc-select use 0.7.6
go func(client *ethclient.Client) {
contractAddresses := []common.Address{}
for _, pair := range Pair {
contractAddresses = append(contractAddresses, common.HexToAddress(pair.PairAddress))
}
SyncEventSig := []byte("Sync(uint112,uint112)")
hash := sha3.NewLegacyKeccak256()
hash.Write(SyncEventSig)
SyncEventHashBytes := hash.Sum(nil)
signature := common.BytesToHash(SyncEventHashBytes) // 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1
topic := []common.Hash{signature}
topics := [][]common.Hash{topic}
query := ethereum.FilterQuery{
Addresses: contractAddresses,
Topics: topics,
}
logs := make(chan types.Log)
sub := event.Resubscribe(2*time.Second, func(ctx context.Context) (event.Subscription, error) {
return client.SubscribeFilterLogs(context.Background(), query, logs)
})
defer sub.Unsubscribe()
for {
select {
case err := <-sub.Err():
log.Fatal("Error on select:", err)
case vLog := <-logs:
fmt.Println("Log block number:", vLog.BlockNumber)
// 여기서 하고 싶은 일 하기.
}
}
}(client)
2.16 부터 기본 동작이 되었다는데, 나는 불편하다. 끄자.
git config --global pager.branch false
참고: https://stackoverflow.com/questions/48341920/git-branch-command-behaves-like-less
pip freeze > requirements.txt
다음과 같은 형식으로 나타날 경우는 pip list --format=freeze > requirements.txt
pytz @ file:///private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_e0y2h1cdsw/croot/pytz_1695131602326/work
이를 이용해 패키지를 설치할 때는 다음과 같이 한다.
pip install --no-cache-dir -r requirements.txt
도커 이미지 빌드 시 사용은 https://hub.docker.com/_/python 를 참고.
## 설치
1.
2.
3.
4.
5.
## 사용 예시
## 문제 해결
## 변경 로그
## 추가 자료
## 라이선스 정보
README 체크리스트
go install github.com/swaggo/swag/cmd/swag
~/go/bin/swag
실행파일이 설치된다.
swag init
docs/docs.go
가 생성된다.
swag fmt
Ethereum의 경우 버전에 따라 트랜잭션에 gasPrice를 쓸 지, maxFeePerGas/maxPriorityFeePerGas 를 쓸 지가 정해진다. https://ethereum.stackexchange.com/questions/147692/how-to-get-public-key-by-the-transaction-hash 를 참고.
주소를 얻을 때, Public key에서 앞의 한 바이트(0x04)를 빼고, keccak256을 돌리는 부분에 유의하자.
const { ethers } = require("hardhat");
// 트랜잭션 서명 값
// const r = "0xe680637b83a1dd102364503bd77979b87c92ba651132a4df8e839af69c20af95";
// const s = "0x65becfa32384747adb05f543397baaf23d1c55fa28d0c9a38924912dae6df28f";
// const v = 12266684226873;
// const chainId = 6133342113419;
// 트랜잭션 해시
const txHash = "0xc7159866fb5b94d291e8624bdc731b7a6d46533b398065de7aa7dd1af7b6aa36";
const ethermainHash = "0xef120deb6ff2e516ad44724d220c0cd73166d169a2a0b0f66dfb5613d2d6169c"
const sepoliaHash = "0xfe4ddad4cae9ea353fc91441ee5db6c70bd5468673d907926be92dd4b8a63f63"
// 실제 트랜잭션에 사용된 private key. 아무거나 넣자.
const privateKey = "0x0000000000000000000000000000000000000000000000000000000000000001";
// Web3 프로바이더 설정 (Hardhat 로컬 노드 사용 예시)
const provider = ethers.provider;
// 서명된 트랜잭션 정보 가져오기
async function getPublicKeyFromTransactionHash(provider, txHash) {
// Fetch the transaction using the transaction hash and provier
const tx = await provider.getTransaction(txHash);
console.log(tx);
// Extract the all the relevant fields from the transaction (We need all of them)
const unsignedTx = {
gasPrice: tx.gasPrice,
gasLimit: tx.gasLimit,
value: tx.value,
nonce: tx.nonce,
data: tx.data,
chainId: tx.chainId,
to: tx.to,
type: tx.type,
// maxFeePerGas: tx.maxFeePerGas,
// maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
};
// Serializing tx without the signature
const serializedTx = ethers.utils.serializeTransaction(unsignedTx);
// Extract the signature (v, r, s) from the transaction
const { v, r, s } = tx;
// Join splitted signature
const signature = ethers.utils.joinSignature({ v, r, s });
const recoveredPublicKey = ethers.utils.recoverPublicKey(
ethers.utils.keccak256(serializedTx),
signature,
);
console.log("recoveredPublicKey:", recoveredPublicKey);
const keccak = ethers.utils.keccak256("0x" + recoveredPublicKey.slice(4))
console.log("keccak256 of recoveredPublicKey:", keccak, ethers.utils.keccak256("0x" + recoveredPublicKey.slice(4)));
// Recover the address or public key with (replace recoverAddress by recoverPublicKey) associated with the transaction
return ethers.utils.recoverAddress(
ethers.utils.keccak256(serializedTx),
signature
);
}
async function main() {
const address = await getPublicKeyFromTransactionHash(provider, txHash);
console.log("Address:", address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
apt-get install -y fonts-nanum
fc-cache -fv
rm ~/.cache/matplotlib -rf
혹은 Windows에서는
from matplotlib import font_manager, rc
font_path = 'C:/Windows/Fonts/NGULIM.TTF'
font = font_manager.FontProperties(fname=font_path).get_name()
rc('font', family=font)
sudo apt-get install fail2ban
sudo systemctl enable fail2ban.service
/etc/fail2ban/
아래에 설정 파일이 있다. jail.d/
아래 파일을 추가/수정.
import { subtask } from "hardhat/config";
import { LedgerSigner } from "@ethers-ext/signer-ledger";
import HIDTransport from "@ledgerhq/hw-transport-node-hid";
const USE_LEDGER = {
"61331819613419": true,
"2022": true
};
subtask("getLedgerSigner", "Get LedgerSigner")
.addOptionalPositionalParam("accountNumber", "Account number of the Ledger", "0")
.setAction(async (taskArgs) => {
const accountNumber = taskArgs.accountNumber;
const chainId = (await ethers.provider.getNetwork()).chainId;
const ledgerNeeded = USE_LEDGER[chainId] ?? false;
console.log("ChainID:", chainId, "LedgerNeeded:", ledgerNeeded);
if (ledgerNeeded) {
const _master = new LedgerSigner(HIDTransport, ethers.provider, `m/44'/60'/${accountNumber}'/0/0`);
_master.getFeeData = async () => {
return {
gasPrice: ethers.BigNumber.from(0),
lastBaseFeePerGas: ethers.BigNumber.from(0),
maxFeePerGas: ethers.utils.parseUnits("800", "gwei"),
maxPriorityFeePerGas: ethers.utils.parseUnits("800", "gwei"),
};
};
console.log(`LedgerSinger: m/44'/60'/${accountNumber}'/0/0:`, await _master.getAddress());
_master.getBalance = async function() {
return await this.provider.getBalance(this.getAddress());
};
return _master;
}
const accounts = await ethers.getSigners();
return accounts[accountNumber];
});
사용할 때는 hre를 이용해서 다음과 같이 하면 된다.
import { task } from "hardhat/config";
import './subtasks/getLedgerSigner';
task("ledgerBalance", "Prints an account's balance")
.addOptionalPositionalParam("accountNumber", "The account number of the ledger", "0")
.setAction(async (taskArgs) => {
const signer = await hre.run("getLedgerSigner", { accountNumber: taskArgs.accountNumber });
console.log("Signer Address:", await signer.getAddress());
const balance = await signer.getBalance();
console.log(ethers.utils.formatEther(balance), "ETH");
});