Building a dApp on the CoinSec Smartchain using secure data entry

We’ll explain how to use the Cryptocurrency Smartchain, BNB tokens and the Chainlink prophecy machine, i.e. learn how to quickly start building externally connected smart contracts on the Cryptocurrency Smartchain (BSC)

Building a dApp on the CoinSec Smartchain using secure data entry

In April 2019, the famous cryptocurrency exchange Binance launched Binance Chain, a network built and optimized for the fast exchange of assets and where the BNB token was born. On the Binance Chain you can.

Send and receive BNB tokens

Issue new tokens

Send, receive, destroy/mint and freeze/unfreeze tokens

Propose to create a transaction pair between two different tokens

Send orders to buy and sell assets via transaction pairs created on the chain

The Cryptocurrency chain is perfect for these users who are looking for faster transactions. However, by design it is not EVM compatible and does not support smart contracts. To enable the creation of smart contracts, the Coinan team also created the Coinan Smart Chain (BSC), a network that uses the Proof of Stake (PoSA) consensus algorithm and is compatible with EVM, enabling smart contract developers to build programmable dApps that naturally integrate with the Coinan chain.

This dual-chain architecture allows for fast transactions on the asset exchange side while also supporting smart contracts. The CoinA team actually coined the term “CeDeFi” or “centralized decentralized finance” to describe this hybrid approach, which strikes a tradeoff between using less decentralized architecture to achieve greater transaction throughput, while still ensuring that developers can deploy applications in a license-free manner and use the same combinable tools available in Ether, such as Solidity and Chainlink feeds.

The Coinlink Smartchain Chainlink Feed is available on the Coinlink mainnet and can be used to build applications on the Coinlink Smartchain (BSC) that require decentralized, tamper-proof data entry. In this technical tutorial, we will explain how to use the Coinan Smartchain, BNB tokens and the Chainlink prophecy machine to learn how to quickly start building externally connected smart contracts on the Coinan Smartchain (BSC), even if you have no experience in Ether development.

Developing with BSC
The tools we will use
Since BSC is compatible with EVM, we can use the same toolset that we would use in the Solidity development environment, such as Truffle, Hardhat, MetaMask, etc. In this tutorial, we will use Brownie, a Python smart contract development framework, to develop on BSC because the Coinan test network does not currently support Chainlink feeds, and the Brownie framework has powerful forked chain features that can be used locally.

If you are interested in using Truffle and Hardhat development on the Coinan smartchain instead of Brownie, check out ganache-cli’s forked chain feature or jump over to where we talk about forks – we’ll cover how to run it on ganache. In fact, it was the ganache-cli fork that Brownie used on the back end when we tested it.

Requirements
python3

nodejs

ganache-cli

brownie

To check the Python version, type in the terminal.

python –version

For nodejs, type.

node -v

You can download python and nodejs by clicking on the text. node comes with npm pre-installed. then make sure ganache-cli is installed with the following command.

npm install -g ganache-cli

or

yarn global add ganache-cli

Finally, install Brownie with the following command:

pip install eth-brownie

or :

pip3 install eth-brownie

Now we are all set!

Getting Started Guide
Now that we have everything set up, go ahead and unbox brownie’s chainlink-mix. this is the sample template for using Chainlink smart contracts. If you want to learn more about it, you can read our blog post on how to deploy smart contracts on any blockchain using python.

To use the main or test network of the Coinlink smartchain, BNB tokens are usually required, similar to using ETH on the ethereum blockchain. to deploy a smart contract, BNB tokens are required.

We will do all the work 100% locally, so we don’t need any test network ETH, LINK or BNB tokens to get started.

First, we need to create the Brownie mix project.

brownie bake chainlink-mix

cd chainlink

Now we go to the project. If we run the ls command, we can see the contents of the directory.

build: this is the folder where the project keeps track of deployed smart contracts and compiled contracts

contracts: the source code of the contracts, usually written in Solidity or Vyper

interfaces: the folder of interfaces needed to interact with the deployed contracts. Each interaction with a contract requires an ABI and a contract address. Interfaces are a good way to get the ABI of a contract

scripts: the scripts we create to automate the contract process

tests: tests

brownie-config.yaml: This file provides Brownie with all the information it needs to understand how to treat our smart contract. What blockchain network do we want to deploy to? Do we want to set any special parameters? All of these are set in this configuration file.

Files such as requirements.txt , README.md , LICENSE , and .gitignore can now be ignored. You will learn what they are used for as you go through the exercise.

We will deploy PriceFeed.sol to our local environment, which will be obtained by forking from the Coinan main chain.

Adding the forked network
In order to use the Cryptocurrency chain, we need a remote procedure call (RPC) link or host field. This is a connection to make an API call to connect to the Coinan Smartchain. If interested, you can also run your own Coinan Smartchain node and connect to that node.

We can find the RPC link for the CoinAsian chain in their documentation. We also need the ChainID. for now, we use the following.

host=https://bsc-dataseed.binance.org/ chainid=56

Finally, we will need the contract addresses of the specific Chainlink feeds to be used. brownie’s chainlink-mix project comes pre-installed with Coinan ETH/USD feeds, but if you want a list of all the Chainlink feeds on Coinan, you can check the Coinan or Chainlink documentation for more information. Look at the brownie-config.yaml file and you will see a section called binance-fork in the networks field. Here are all the variables we need to use the Coinlink fork chain.

Now, we are going to tell Brownie to make a connection to the Coinan chain, but we are going to fork this chain. Forking a chain means copying that chain and running it locally so we don’t have to pay any gas fees and we can iterate and test it quickly. But it also means that if the forked chain drops, everything will be deleted! We can add a fork of the Coinan chain to the Brownie network using the following command.

brownie networks add development binance-fork cmd=ganache-cli host=http://127.0.0.1 fork=https://bsc-dataseed1.binance.org accounts=10 mnemonic=brownie port=8545

This will run the local ganache-cli chain on port 8545 of the local host. It will use https://bsc-dataseed1.binance.org作为分叉源 at deployment time. If done correctly, you will see something like the following.

Brownie v1.13.0 – Python development framework for Ethereum

SUCCESS: A new network ‘binance-fork’ has been added

└─binance-fork

├─id: binance-fork

├─cmd: ganache-cli

├─cmd_settings: {‘fork’: ‘https://bsc-dataseed1.binance.org’, ‘accounts’: 10, ‘mnemonic’: ‘brownie’, ‘port’: 8545}

└─host: http://127.0.0.1

You can run brownie networks list to check all networks.

Deploying the contract
Now that everything is set up, we can deploy and read the contracts on the local ganache fork chain. In the scripts folder, there is a script called deploy_price_consumer_v3.py. We can run it with the following command.

brownie run scripts/price_feed_scripts/deploy_price_consumer_v3.py –network binance-fork

You will see output similar to the following.

Brownie v1.13.0 – Python development framework for Ethereum

ChainlinkMixProject is the active project.

Launching ‘ganache-cli –accounts 10 –fork https://bsc-dataseed1.binance.org –mnemonic brownie –port 8545 –hardfork istanbul’ …

Running ‘scripts/price_feed_scripts/deploy_price_consumer_v3.py::main’…

Transaction sent: 0x63022ee6c741ffb31ec6f8f29d3d2412c0a81a557a316a9a9752603825b8e96d

Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 0

PriceFeed.constructor confirmed – Block: 4398765 Gas used: 132364 (1.97%)

PriceFeed deployed at: 0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87

The current price of ETH is 135462000000

Terminating local RPC client…

So, we have just completed.

Forking the Coin On chain and running it locally

Deploy a smart contract to it

and read the price of ETH from it

The current price of ETH is 135462000000

Congratulations! You’re one step closer to getting some CoinAid bounty!

One step further
Now that you know how to deploy smart contracts using the Cryptocurrency Smartchain, you can also delve deeper into BSC, or use other sidechains like Matic, xDai, and other Layer 2 networks. If you prefer Hardhat and Truffle frameworks, see if you can execute ganache-cli commands in those frameworks and run some local tests. There are a number of hackathons coming up, so be sure to attend one of these to seek out opportunities to collaborate with other talent in the field, win some awards, and grow yourself into a true smart contract developer.

If you want to continue to expand the capabilities of smart contracts, visit the Chainlink developer documentation and join the technical discussions in Discord. If you’ve built nice projects using Coinan Smartchain, Brownie, Truffle, Hardhat or any other Chainlink integration, be sure to tag us using @chainlink so we can see the great work you’ve done!

Posted by:CoinYuppie,Reprinted with attribution to:https://coinyuppie.com/building-a-dapp-on-the-coinsec-smartchain-using-secure-data-entry/
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Like (0)
Donate Buy me a coffee Buy me a coffee
Previous 2021-05-22 13:15
Next 2021-05-22 13:21

Related articles