1591496065
ERC20 token contract has several functions that you must know how to use.
In this video I will explain how to use those functions, transfer, approve and transferFrom.
ERC20
Any contract that follow the ERC20 standard is a ERC20 token.
ERC20 tokens provide functionalities to transfer tokens allow others to transfer tokens on behalf of the token holder
Here is the interface for ERC20.
pragma solidity ^0.6.0;
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
Using Open Zeppelin it’s really easy to create your own ERC20 token.
Here is an example
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor (string memory name, string memory symbol)
ERC20(name, symbol)
public
{
// Mint 100 tokens to msg.sender
// Similar to how
// 1 dollar = 100 cents
// 1 token = 1 * (10 ** decimals)
_mint(msg.sender, 100 * 10 ** uint(decimals()));
}
}
Here is an example contract, TokenSwap, to trade one ERC20 token for another.
This contract will swap tokens by calling
transferFrom(address sender, address recipient, uint256 amount)
which will transfer amount of token from sender to recipient.
For transferFrom to succeed, sender must
have more than amount tokens in their balance
allowed TokenSwap to withdraw amount tokens by calling approve
prior to TokenSwap calling transferFrom
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol";
/*
How to swap tokens
1. Alice has 100 tokens from AliceCoin, which is a ERC20 token.
2. Bob has 100 tokens from BobCoin, which is also a ERC20 token.
3. Alice and Bob wants to trade 10 AliceCoin for 20 BobCoin.
4. Alice or Bob deploys TokenSwap
5. Alice appproves TokenSwap to withdraw 10 tokens from AliceCoin
6. Bob appproves TokenSwap to withdraw 20 tokens from BobCoin
7. Alice or Bob calls TokenSwap.swap(10, 20)
8. Alice and Bob traded tokens successfully.
*/
contract TokenSwap {
IERC20 public token1;
address public owner1;
IERC20 public token2;
address public owner2;
constructor(
address _token1,
address _owner1,
address _token2,
address _owner2
) public {
token1 = IERC20(_token1);
owner1 = _owner1;
token2 = IERC20(_token2);
owner2 = _owner2;
}
function swap(uint _amount1, uint _amount2) public {
require(msg.sender == owner1 || msg.sender == owner2, "Not authorized");
require(
token1.allowance(owner1, address(this)) >= _amount1,
"Token 1 allowance too low"
);
require(
token2.allowance(owner2, address(this)) >= _amount2,
"Token 2 allowance too low"
);
_safeTransferFrom(token1, owner1, owner2, _amount1);
_safeTransferFrom(token2, owner2, owner1, _amount2);
}
function _safeTransferFrom(
IERC20 token,
address sender,
address recipient,
uint amount
) private {
bool sent = token.transferFrom(sender, recipient, amount);
require(sent, "Token transfer failed");
}
}
Code: https://solidity-by-example.org/0.6/app/erc20/
Truffle: https://www.trufflesuite.com/docs/truffle/overview
Remix IDE: http://remix.ethereum.org
Solidity: https://solidity.readthedocs.io
#erc20 #ethereum #solidity #contract
1600983316
superb! Thanks!
1616568076
The Blockchain App Factory is a leading industry with Ethereum Token development platform that offers services like Token creation, Token migration, Token Listing, Secured Storage, ICO development, ERC token wallet. They also build and generate Ethereum tokens such as ERC 20, ERC 721, ERC 777.
#erc token development #ethereum token development company #ethereum token development services #ethereum(erc) token development services #erc 20 development #erc 721 development
1591496065
ERC20 token contract has several functions that you must know how to use.
In this video I will explain how to use those functions, transfer, approve and transferFrom.
ERC20
Any contract that follow the ERC20 standard is a ERC20 token.
ERC20 tokens provide functionalities to transfer tokens allow others to transfer tokens on behalf of the token holder
Here is the interface for ERC20.
pragma solidity ^0.6.0;
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
Using Open Zeppelin it’s really easy to create your own ERC20 token.
Here is an example
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor (string memory name, string memory symbol)
ERC20(name, symbol)
public
{
// Mint 100 tokens to msg.sender
// Similar to how
// 1 dollar = 100 cents
// 1 token = 1 * (10 ** decimals)
_mint(msg.sender, 100 * 10 ** uint(decimals()));
}
}
Here is an example contract, TokenSwap, to trade one ERC20 token for another.
This contract will swap tokens by calling
transferFrom(address sender, address recipient, uint256 amount)
which will transfer amount of token from sender to recipient.
For transferFrom to succeed, sender must
have more than amount tokens in their balance
allowed TokenSwap to withdraw amount tokens by calling approve
prior to TokenSwap calling transferFrom
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol";
/*
How to swap tokens
1. Alice has 100 tokens from AliceCoin, which is a ERC20 token.
2. Bob has 100 tokens from BobCoin, which is also a ERC20 token.
3. Alice and Bob wants to trade 10 AliceCoin for 20 BobCoin.
4. Alice or Bob deploys TokenSwap
5. Alice appproves TokenSwap to withdraw 10 tokens from AliceCoin
6. Bob appproves TokenSwap to withdraw 20 tokens from BobCoin
7. Alice or Bob calls TokenSwap.swap(10, 20)
8. Alice and Bob traded tokens successfully.
*/
contract TokenSwap {
IERC20 public token1;
address public owner1;
IERC20 public token2;
address public owner2;
constructor(
address _token1,
address _owner1,
address _token2,
address _owner2
) public {
token1 = IERC20(_token1);
owner1 = _owner1;
token2 = IERC20(_token2);
owner2 = _owner2;
}
function swap(uint _amount1, uint _amount2) public {
require(msg.sender == owner1 || msg.sender == owner2, "Not authorized");
require(
token1.allowance(owner1, address(this)) >= _amount1,
"Token 1 allowance too low"
);
require(
token2.allowance(owner2, address(this)) >= _amount2,
"Token 2 allowance too low"
);
_safeTransferFrom(token1, owner1, owner2, _amount1);
_safeTransferFrom(token2, owner2, owner1, _amount2);
}
function _safeTransferFrom(
IERC20 token,
address sender,
address recipient,
uint amount
) private {
bool sent = token.transferFrom(sender, recipient, amount);
require(sent, "Token transfer failed");
}
}
Code: https://solidity-by-example.org/0.6/app/erc20/
Truffle: https://www.trufflesuite.com/docs/truffle/overview
Remix IDE: http://remix.ethereum.org
Solidity: https://solidity.readthedocs.io
#erc20 #ethereum #solidity #contract
1620729846
Can you use WordPress for anything other than blogging? To your surprise, yes. WordPress is more than just a blogging tool, and it has helped thousands of websites and web applications to thrive. The use of WordPress powers around 40% of online projects, and today in our blog, we would visit some amazing uses of WordPress other than blogging.
What Is The Use Of WordPress?
WordPress is the most popular website platform in the world. It is the first choice of businesses that want to set a feature-rich and dynamic Content Management System. So, if you ask what WordPress is used for, the answer is – everything. It is a super-flexible, feature-rich and secure platform that offers everything to build unique websites and applications. Let’s start knowing them:
1. Multiple Websites Under A Single Installation
WordPress Multisite allows you to develop multiple sites from a single WordPress installation. You can download WordPress and start building websites you want to launch under a single server. Literally speaking, you can handle hundreds of sites from one single dashboard, which now needs applause.
It is a highly efficient platform that allows you to easily run several websites under the same login credentials. One of the best things about WordPress is the themes it has to offer. You can simply download them and plugin for various sites and save space on sites without losing their speed.
2. WordPress Social Network
WordPress can be used for high-end projects such as Social Media Network. If you don’t have the money and patience to hire a coder and invest months in building a feature-rich social media site, go for WordPress. It is one of the most amazing uses of WordPress. Its stunning CMS is unbeatable. And you can build sites as good as Facebook or Reddit etc. It can just make the process a lot easier.
To set up a social media network, you would have to download a WordPress Plugin called BuddyPress. It would allow you to connect a community page with ease and would provide all the necessary features of a community or social media. It has direct messaging, activity stream, user groups, extended profiles, and so much more. You just have to download and configure it.
If BuddyPress doesn’t meet all your needs, don’t give up on your dreams. You can try out WP Symposium or PeepSo. There are also several themes you can use to build a social network.
3. Create A Forum For Your Brand’s Community
Communities are very important for your business. They help you stay in constant connection with your users and consumers. And allow you to turn them into a loyal customer base. Meanwhile, there are many good technologies that can be used for building a community page – the good old WordPress is still the best.
It is the best community development technology. If you want to build your online community, you need to consider all the amazing features you get with WordPress. Plugins such as BB Press is an open-source, template-driven PHP/ MySQL forum software. It is very simple and doesn’t hamper the experience of the website.
Other tools such as wpFoRo and Asgaros Forum are equally good for creating a community blog. They are lightweight tools that are easy to manage and integrate with your WordPress site easily. However, there is only one tiny problem; you need to have some technical knowledge to build a WordPress Community blog page.
4. Shortcodes
Since we gave you a problem in the previous section, we would also give you a perfect solution for it. You might not know to code, but you have shortcodes. Shortcodes help you execute functions without having to code. It is an easy way to build an amazing website, add new features, customize plugins easily. They are short lines of code, and rather than memorizing multiple lines; you can have zero technical knowledge and start building a feature-rich website or application.
There are also plugins like Shortcoder, Shortcodes Ultimate, and the Basics available on WordPress that can be used, and you would not even have to remember the shortcodes.
5. Build Online Stores
If you still think about why to use WordPress, use it to build an online store. You can start selling your goods online and start selling. It is an affordable technology that helps you build a feature-rich eCommerce store with WordPress.
WooCommerce is an extension of WordPress and is one of the most used eCommerce solutions. WooCommerce holds a 28% share of the global market and is one of the best ways to set up an online store. It allows you to build user-friendly and professional online stores and has thousands of free and paid extensions. Moreover as an open-source platform, and you don’t have to pay for the license.
Apart from WooCommerce, there are Easy Digital Downloads, iThemes Exchange, Shopify eCommerce plugin, and so much more available.
6. Security Features
WordPress takes security very seriously. It offers tons of external solutions that help you in safeguarding your WordPress site. While there is no way to ensure 100% security, it provides regular updates with security patches and provides several plugins to help with backups, two-factor authorization, and more.
By choosing hosting providers like WP Engine, you can improve the security of the website. It helps in threat detection, manage patching and updates, and internal security audits for the customers, and so much more.
#use of wordpress #use wordpress for business website #use wordpress for website #what is use of wordpress #why use wordpress #why use wordpress to build a website
1595575618
ERC20 token is a like a Lego block that you can build on top of. In this video I will show you how you can code a contract that will trade one ERC20 token for another.
Code: https://solidity-by-example.org/0.6/a…
Truffle: https://www.trufflesuite.com/docs/tru…
Remix IDE: http://remix.ethereum.org
Solidity: https://solidity.readthedocs.io
#erc-20 #blockchain #bitcoin
1619571780
March 25, 2021 Deepak@321 0 Comments
Welcome to my blog, In this article, we will learn the top 20 most useful python modules or packages and these modules every Python developer should know.
Hello everybody and welcome back so in this article I’m going to be sharing with you 20 Python modules you need to know. Now I’ve split these python modules into four different categories to make little bit easier for us and the categories are:
Near the end of the article, I also share my personal favorite Python module so make sure you stay tuned to see what that is also make sure to share with me in the comments down below your favorite Python module.
#python #packages or libraries #python 20 modules #python 20 most usefull modules #python intersting modules #top 20 python libraries #top 20 python modules #top 20 python packages