DEPLOYING SMART CONTRACTS TO TEST NETWORK

Mutahhir Khan
4 min readSep 20, 2021

GitHub link to write smart contracts and deploy to Rinkeby and main-net network

GitHub link to build oracle

Advance Solidity concept and deployment

  • TESTING ON TRUFFLE :

Before deploying call contracts to mainnet/basechain. Developers should run a unit test and proper privacy checks. Once the contracts put to the mianent it can’t be modifiable and it can cause the privacy leakage and security issues. For this some of the test networks has been released and some test gets runs like hardhat, truffle. These test runs on local machine and remix testing it server testing where the call contract deployed instantly and gets tested.

Test starts by using artifacts. Artifacts objects injected by the truffle framework inside this test file and this object has method require that allows you to import this contract artifact, name has to be the exactly same as of the contract to test.

Because our contract follows some sort of timing functions to freeze the zombie for a certain time duration before attacking again so we import these too.

Create the contract instance so that it contains all the methods that you want to use.

In order to run a test, a callback passes into a contract function which has to be async where our test function “it” defined. Every test we run, has to be a function named “it” later we’ll talk about context. It takes two params, first the check. Check can be of ay sort like “my contract is super-duper cool” second is a callback which has to be async because it communicates to our contacts on the network.

Now your instance should be pointing to the method you are using. If that method contains event, then the logs can be found as result which contains some useful information like name, id etc.

You would be curious that if I’ve too many contracts to written to test and if I want to run only the last then it would take too much to reach to bottom. Don’t worry, we have a solution for this. Just put an ‘x’ character before “it” then it would skip the testing for that particular function.

To make a group test, truffle has function named “context” which lets you write multiple “it” functions to run parallelly. It’s same as it. Just wrap “it” around another “it” and named it “context”.

run the command $ truffle test to start the testing.

  • DEPLOY TO RINKEBY TEST NETWORK :

Deployment to any testnet or any mainnet doesn’t require much effort. But make sure thing that your contract should be flawless and all the security check have been safeguarded. Let’s configure the truffle.js file in the root directory of your folder and import @truffle/hdwallet provider in it. Prepare you own 12 words long mnemonic so that it unifies your deployment in any manner. Get your api keys for the network you wanna deploy. Now start with a network object which contains a Rinkeby object having a provider which would be a function and a networkId (pre-defined of network). In the provider function it returns a new object of hdwalletProvider (which you imported above) with a parameter of your mnemonic and your network apikey.

That all for the config. Now run truffle init to prepare your folder hierarchy and then run command $ truffle migrate — network rinkeby. This rinkeby has to be exact name as of your network object’s entity.

  • DEPLOY TO BASECHAIN NETWORK ( MAINNET ) :

Deploying to base-chain is of no wonder if you have done deploying to test networks. The process is the same but there’s no going back. It’s an irreversible process. Follow all the exact same rules createa and object name basechain in networks object. Setup the basic configuration, read, write urls chainId etc. you can have these from the internet also https://github.com/mutahhirkhan/contracts/blob/main/truffle.js .

  • BUILDING AND ORACLE

building and interact with the simplest possible oracle that allows only one user, its owner, to fetch data from Binance’s public API.

Building oracle for users is just like attaching a middleware between user and real-time changes in the network. The oracle keeps the record of the things that we want him to keep like price update, coin release, market rate etc.

Oracle doesn’t contain that much code as compared to usual contract. Most of the time it inherits interfaces and define modifiers which allows users to update the state. For example, once user purchases some part of any random coin, then at a maximum price then the oracle event would trigger and set the new purchased price as the current market price. That what oracle uses for. My intension was not the limit the oracle functionality, it’s just a single case, may be you could write something more useful to oracle and facilitate the users.

--

--