Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Smart Contract Developer, Web3 Backend Developer
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Smart Contract Developer, Web3 Backend Developer

Subscribe to Primrose

Subscribe to Primrose
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers
https://docs.alchemy.com/docs/how-to-develop-an-nft-smart-contract-erc721-with-alchemy
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts@4.7.3/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.7.3/utils/Counters.sol";
// Alchemy는 이름, ERC721 이하는 모두 상속을 받은 컨트랙트들
contract Alchemy is ERC721, ERC721Enumerable, ERC721URIStorage {
using Counters for Counters.Counter;
// private, public, internal, external ...
// private은 스마트 컨트랙트 내에서만 보이고, 내부에서만 수행할 수 있다.
Counters.Counter private _tokenIdCounter;
// MAX NUMBER OF COUNTERS
uint256 MAX_SUPPLY = 10000;
// 생성자, Alchemy는 이름, ALCH는 Symbol
constructor() ERC721("Alchemy", "ALCH") {}
// minting은 새로운 토큰 혹은 엔트리를 만들어 내는 행위
// action of create a new entry or thing onto the blockchain
// nft를 전송할 wallet의 주소, token uri를 받는다
// public 과 onlyOwner 를 이용해서 모두가 보고 사용할 수 있다.
function safeMint(address to, string memory uri) public {
// 현재 토큰 id를 카운터에서 가져온다.
uint256 tokenId = _tokenIdCounter.current();
// MAX_SUPPLY에 도달했는지 검사
require(tokenId <= MAX_SUPPLY, "I'm sorry all NFTs have been minted");
// 토큰 id 증가
_tokenIdCounter.increment();
// nft 민팅
_safeMint(to, tokenId);
// token uri 세팅
_setTokenURI(tokenId, uri);
}
// The following functions are overrides required by Solidity.
// overribe 한 메소드들
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}
// internal은 private과 비슷하지만, 컨트랙트 내부 혹은 상속된 컨트랙트에서 호출할 수 있다.
function _burn(uint256 tokenId)
internal
override(ERC721, ERC721URIStorage)
{
super._burn(tokenId);
}
// tokenId를 넘기고 tokenUri를 리턴 받는다.
// view는 reading 역할을 담당하는 modifier
// write하지 않겠다는 의미, gas가 발생하지 않는다 !
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
https://docs.alchemy.com/docs/how-to-develop-an-nft-smart-contract-erc721-with-alchemy
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts@4.7.3/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.7.3/utils/Counters.sol";
// Alchemy는 이름, ERC721 이하는 모두 상속을 받은 컨트랙트들
contract Alchemy is ERC721, ERC721Enumerable, ERC721URIStorage {
using Counters for Counters.Counter;
// private, public, internal, external ...
// private은 스마트 컨트랙트 내에서만 보이고, 내부에서만 수행할 수 있다.
Counters.Counter private _tokenIdCounter;
// MAX NUMBER OF COUNTERS
uint256 MAX_SUPPLY = 10000;
// 생성자, Alchemy는 이름, ALCH는 Symbol
constructor() ERC721("Alchemy", "ALCH") {}
// minting은 새로운 토큰 혹은 엔트리를 만들어 내는 행위
// action of create a new entry or thing onto the blockchain
// nft를 전송할 wallet의 주소, token uri를 받는다
// public 과 onlyOwner 를 이용해서 모두가 보고 사용할 수 있다.
function safeMint(address to, string memory uri) public {
// 현재 토큰 id를 카운터에서 가져온다.
uint256 tokenId = _tokenIdCounter.current();
// MAX_SUPPLY에 도달했는지 검사
require(tokenId <= MAX_SUPPLY, "I'm sorry all NFTs have been minted");
// 토큰 id 증가
_tokenIdCounter.increment();
// nft 민팅
_safeMint(to, tokenId);
// token uri 세팅
_setTokenURI(tokenId, uri);
}
// The following functions are overrides required by Solidity.
// overribe 한 메소드들
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}
// internal은 private과 비슷하지만, 컨트랙트 내부 혹은 상속된 컨트랙트에서 호출할 수 있다.
function _burn(uint256 tokenId)
internal
override(ERC721, ERC721URIStorage)
{
super._burn(tokenId);
}
// tokenId를 넘기고 tokenUri를 리턴 받는다.
// view는 reading 역할을 담당하는 modifier
// write하지 않겠다는 의미, gas가 발생하지 않는다 !
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
No activity yet