Skip to content

Instantly share code, notes, and snippets.

@toddstephens335
Created October 2, 2023 23:55
Show Gist options
  • Save toddstephens335/5782ab4c0da9cf853275bdbbe4ef74a9 to your computer and use it in GitHub Desktop.
Save toddstephens335/5782ab4c0da9cf853275bdbbe4ef74a9 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.19-nightly.2023.2.9+commit.59f9ab4d.js&optimize=true&runs=200&gist=
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
ref: refs/heads/main
DIRCeE4��eE4��*�����o#q{K���Sc��X�W�n.prettierrc.jsoneE'���eE'���$���� ��2I3�\��owi�זcontracts/MyToken.soleE*r@eE*r@&���cS?���5?,���7��'�|scripts/deploy_with_ethers.tseE.�_�eE.�_�'������.��E�r���NH-��Wscripts/deploy_with_web3.tseE1,�@eE1,�@(���'S��Н��M�%5�s<��wscripts/ethers-lib.tseE3�@eE3�@)��%�tW*����aJ;�c�fY��scripts/web3-lib.ts(�zh�=q�q+#�ݻM@o�
x�+)JMU0�d040031Q� ��N��+��axۧ0���S�x�P̯���̧קe��
x�+)JMU047c040031QHI-�ɯ�/�,ɈO-�H-*�+)fH���u����N��^��w�`�P��d R.�j�t���]o�<���C�m�x8T9�Lݜ�$�B���{.�}���`����b�gʡ
Af��M/ �j������e}"�XZ�����G�
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�]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���A
�0@Q�9�\@�4�Ĉ�[���Sh��� �^е;�?�R�@g�N3�q�����9 ]�{k9h�E���D���j�ð �/�1t����C��?�� �;R�{��*}6���ے%��� ����Q�[ҚH��[R�
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�mT_k�0߳?�= �Tn l`�n�Ơ���>�a "�G�-InR��d��F ��~�t�V9\ͯ>��Vi ?1��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��#�s
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��Uێ�0�s��� $ �J������R�E� U�Z�$��ؑ/eÊ���pIQWK^�g�g�9f��ˀ\�F���>y�}�>��B��a1uC�s/Ut�P�%g3�5�~�xKR� �����8~(�Q44z`ӕ�Ѐ�o�o�燏WW�q�^4C��L^I����mD�|���*�Ϩկ�;T O�eR�:tg�H�J>e�5�k*�a�������)3��H�y��0M���������I��ns�7}rD�<{�����F&7r[�AaB��s�!H[eC#U�io��U@���X��I���I��y�+�"4x����h��6�,�G]V��yY�ө�\�M�;�����|j�8r��X��x�v�&V$�D����8�j9R� ���=a�ƪ�<E�E�p��v+��U��$L�.�"���[CZa��b�z�����M�2dtmFD ��f%�t|����i�,oR�x�fzGM�vt�t�~���H�DK|}1�%��@����� �
��a���1('o!Eq����J&���Rq��pجA|�&�,� ��R,�#�E��V=������֬��ˢPg�4I9$���y�)��v*c������[
x�+)JMU044a040031Q�+(J-)�L-*J��*��cش4_���{v?���#����31��������b��?��%3r�X��e�7�Kz~5��E�@<�G�������7k��C��)���/�
3a8b249c213064a824eb07b79eb29992757ad96e
{
"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/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract MyToken is Initializable, ERC1155Upgradeable, OwnableUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable, UUPSUpgradeable {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize() initializer public {
__ERC1155_init("");
__Ownable_init();
__Pausable_init();
__ERC1155Burnable_init();
__UUPSUpgradeable_init();
}
function setURI(string memory newuri) public onlyOwner {
_setURI(newuri);
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function mint(address account, uint256 id, uint256 amount, bytes memory data)
public
onlyOwner
{
_mint(account, id, amount, data);
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
public
onlyOwner
{
_mintBatch(to, ids, amounts, data);
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyOwner
override
{}
}
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 || 3600000
})
return newContractInstance.options
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment