Skip to content

Instantly share code, notes, and snippets.

@charlieskc
Created August 27, 2023 05:35
Show Gist options
  • Save charlieskc/aaaedf915fe6e3ef3632812dc6a26ffa to your computer and use it in GitHub Desktop.
Save charlieskc/aaaedf915fe6e3ef3632812dc6a26ffa to your computer and use it in GitHub Desktop.
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.18+commit.87f61d96.js&optimize=false&runs=200&gist=
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
ref: refs/heads/main
DIRCd��."M�d��."M�$�����o#q{K���Sc��X�W�n.prettierrc.jsond��*�πd��*�π��e$����Lk�\�4�7�����contracts/MyToken.sold��+�od��+�o ���cS?���5?,���7��'�|scripts/deploy_with_ethers.tsd��,�P�d��,�P�!������.��E�r���NH-��Wscripts/deploy_with_web3.tsd��-�d��-�"���'S��Н��M�%5�s<��wscripts/ethers-lib.tsd��-��@d��-��@#��%�~P9���WrV���ߒ�~�scripts/web3-lib.tsO��RG���ُ��'��W 
x�M��
�0D��7I@���P���M�&m�bڔ$RBɿ[k���;e��f��Uuk]@�R��F$\��AŪ�j�4���0�cS�qd�.� ��N�� � ;Y�i��c<هn�� ���ha��,��1�?bjR��
�;��g_[�z �M�(I���B�
x���]O�0��ޯ8��HU����Ţ�F1�JR�BN,��v�a��vc�!^��iz�{���3�f�� ����۷�2. oG �����h⥚.���������� F���Ti �X�\nx�r��0%��̚v�.4M8� N�����=�\u/�����8�?�=�����J�*r�iY��ve�CW��J�Z�$�( �$Z�7 �W�A�O��  C8�[���Nmçn��c���C��]:���9oS!�
�cuƬ�eQ��*P�� ����ʵ Z�2���m�If���5q8hH��@֤Nw�M U�W#�C��ɽ_��z��#A5���wgE�1J�$�����2�^���jQҪm*)ru��������/�z_<�&=
x�]SMo�0 �ٿ����@�>C�v�:耦Z`��6���%CR�A�{)�#�r0"�||���ç�_�}�m����ې�p�����GQvv�����{�[�� )(�r �vh���uF��8���%P����:>��P�y��1�?G��<��B#������iC&��湫m��ἢ�[�nUI��d8a��v�R9>Cnk��ǁ�͔f��e��!.�^��u/�wc�,�$n��%��=]�3���{����..�C��"�uC��u��p�x�W?�S�2XiG,]Pn #;�������-�6�؀�P�"��%OV��d�Nj�:��_��w���f�U������2,��� ��m��un�Β�FD�M!�ų�j�\oP�^$����RV�w M�xh�D�\����J��XJp�ҁ�V���&�+��
k2��� �ċ�t���xG�n܋,9�[�=Լd�� �y�;�?��"�Ǒ��5�ŒE�aE7�Y�w��� ��`^�!;��Sz��j��s�=��M������b�H�O�wT�D�|1����:�+|j�~.!���t]��i�~^V�O�Mۓ�;�v���e�dm�
��WA��� k<��� }�V
x�+)JMU047c040031QHI-�ɯ�/�,ɈO-�H-*�+)fH���u����N��^��w�`�P��d R.�j�t���]o�<���C�m�x8T9�Lݜ�$�B���{.�}���`����b�gʡ
Af��� �\��-�(l��g��'u���I5
x�M��
�@�;�svʢC��ޠ[�\�O��_v7Bd�=3�N���d�3��E�tl=��p��@��Y�6u&�Hj׷9�Br���S9��Ò{���k?�Iq��|�V�p��ΆbåLuQ��;`9|� �ȵ�+HRg_��f$uI%� ��C�
x���A
�0=�{J6i�VD���Ͳ���H�����os���d��M8���a�>I�c����(xX�u� x��f���-�׺�Z��q-�8y�>�G;Zk�sU��7�{�L+|C'hR�T�c%�/i<84o�oG
x����
�0 �=�)F�2ă��-D��xh�L��)m&�ػ�6�1�9%��|��"�m�E�M1|��2����?�U���
�<��+��%� I�m>\�R�Y�to�t���E�oF������^p�`�pR�J$������hx��8��~������N񯌇���=ꐶ������5��/�̢�
x�mT_k�0߳?�= �Tn(c`�n�Ơ���>�a "�G�-InR��d��F ��~�t�V9̯�߉f�����_�Z����Qx��JZ� ;�P��h7�����
% t��.��GQz~�9|�m��`7�xA C� ~�r�8����1�� �tj��C���3N� ������m\Wja������*�OF�ڜ����P���,�����>�KC�T�,�&G�Aō�բ}am�%B����h'����~{�!n���, �v#�������䙷��@F詷v��#E�����nn�ED�ё�ĝ���=�E��Y�FV�*Y�I��KMSX*K��p�f
-����4�����6�؀���D�-����?�f+j�R�V��������z2 �����A Cwx�K��n��U��ΠNF��)��g����6$^rˉ���Ò�@L�� ��
^�I�&w�\�
u<��B���ij͜��� 7�Ν��b^�`2 >�qU!��`��\��p;���x�RX?Ɂ��+���_��X��ʟ�� >���m��g~��]7�'���=sY�X��s ���d�輽�]�u���-��NRp���]�(@���L�]Q���p
x�+)JMU044a040031Q�+(J-)�L-*J��*��cش4_���{v?���#����31��������b�?b5�7��� #˚S�.�D�탨)N.�,��ڸI�q����x���m��� <A2�
x�+)JMU0�d040031Q� ��N��+��aPy����Q��1�L��7��SvuB�
8cd676185bce4857e35ae52e1e6c0c89a9ed00d1
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
},
{
"files": "*.yml",
"options": {}
},
{
"files": "*.yaml",
"options": {}
},
{
"files": "*.toml",
"options": {}
},
{
"files": "*.json",
"options": {}
},
{
"files": "*.js",
"options": {}
},
{
"files": "*.ts",
"options": {}
}
]
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract MyToken is Initializable, ERC721Upgradeable, ERC721BurnableUpgradeable, OwnableUpgradeable {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize() initializer public {
__ERC721_init("MyToken", "MTK");
__ERC721Burnable_init();
__Ownable_init();
}
function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
}
import { deploy } from './ethers-lib'
(async () => {
try {
const result = await deploy('MyToken', [])
console.log(`address: ${result.address}`)
} catch (e) {
console.log(e.message)
}
})()
import { deploy } from './web3-lib'
(async () => {
try {
const result = await deploy('MyToken', [])
console.log(`address: ${result.address}`)
} catch (e) {
console.log(e.message)
}
})()
import { ethers } from 'ethers'
/**
* Deploy the given contract
* @param {string} contractName name of the contract to deploy
* @param {Array<any>} args list of constructor' parameters
* @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract
*/
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
const contract = await factory.deploy(...args)
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
return contract
}
import Web3 from 'web3'
import { Contract, ContractSendMethod, Options } from 'web3-eth-contract'
/**
* Deploy the given contract
* @param {string} contractName name of the contract to deploy
* @param {Array<any>} args list of constructor' parameters
* @param {string} from account used to send the transaction
* @param {number} gas gas limit
* @return {Options} deployed contract
*/
export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {
const web3 = new Web3(web3Provider)
console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json`
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const accounts = await web3.eth.getAccounts()
const contract: Contract = new web3.eth.Contract(metadata.abi)
const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})
const newContractInstance = await contractSend.send({
from: from || accounts[0],
gas: gas || 1500000
})
return newContractInstance.options
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment