The Azure Blockchain Development Kit for Ethereum extension for Visual Studio Code (VS Code) supports OpenZeppelin Contracts.
You can read all the details in the Microsoft announcement:
The following guide will walk through using the Azure Blockchain Development Kit for Ethereum with OpenZeppelin Contracts to create an ERC20 token, including deploying and interacting.
Prerequisites
If you haven’t already, install VS Code as per the instructions on the website:
Setup
Install Azure Blockchain Development Kit for Ethereum extension by selecting install from the website:
https://marketplace.visualstudio.com/items?itemName=AzBlockchain.azure-blockchain
Create a new project
Create an empty directory for your new project e.g. mkdir demo
Open VS Code
From the VS Code Command Palette (View menu -> Command Palette), type Azure Blockchain: New Solidity Project
Then Select type of solidity project
choose Create basic project
Then choose the empty directory you created previously.
This will do a truffle unbox of Azure-Samples/Blockchain-Ethereum-Template
so could be a good time to make a cup of tea.
Add OpenZeppelin Contracts
Select an existing contract in the contracts directory e.g. Migrations.sol
and open the context menu (e.g. in Windows right click).
Choose Add contracts from OpenZeppelin
Then Select category for downloading
and choose Tokens/ERC20
This will download the OpenZeppelin Contracts for ERC20 Tokens in contracts/openZeppelin
.
The contracts in contracts/openZeppelin
are read only so that you can’t save any changes.
Create an ERC20 Token
We will now create a simple ERC20 token where the total supply will be issued to the deployer of the contract.
In the contracts
directory create a file named SimpleToken.sol
.
Paste the following smart contract code into SimpleToken.sol
.
We can see that the contract imports from the OpenZeppelin contracts we just added to our project.
pragma solidity ^0.5.0;
import "./openZeppelin/token/ERC20/ERC20.sol";
import "./openZeppelin/token/ERC20/ERC20Detailed.sol";
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `ERC20` functions.
*/
contract SimpleToken is ERC20, ERC20Detailed {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor () public ERC20Detailed("SimpleToken", "SIM", 18) {
_mint(msg.sender, 10000 * (10 ** uint256(decimals())));
}
}
Migrations
In the migrations
directory, we can replace the contents of 2_deploy_contract.js
with the following:
var SimpleToken = artifacts.require("SimpleToken");
module.exports = deployer => {
deployer.deploy(SimpleToken);
};
We don’t need 99_deploy_openzeppelin.js
so this can be deleted.
Deploy
First start a local blockchain in a terminal (ganache-cli -d
).
From the Command Palette, type Azure Blockchain: Deploy Contracts
(or select one of the contracts in the contracts
directory e.g. SimpleToken.sol
and from the context menu choose Deploy Contracts
).
You will be asked Some contracts have parameters required for deploy. Do you want to specify them?
. You can select No
and delete the newly created 99_deploy_openzeppelin.js
.
Then select development 127.0.0.1:8545
to deploy to a local test network (ganache-cli
)
Interact
Select SimpleToken.sol
in the contracts
directory and from the context menu choose Show Smart Contract Interaction Page
This will display a Smart Contract UI for the SimpleToken.
Currently read functions that take parameters such as balanceOf
and allowance
are not supported.
Change the Contract Action
to transfer
.
Set the recipient to an address e.g. 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
Set the amount e.g. 23
Press the Execute
button to create a transaction.
Next steps
We can also deploy to public networks such as public testnets or mainnet using Infura.
See the Infura blog post for instructions: