Development

Deploying smart contract on BPX mainnet using Remix IDE

  1. Open the Remix IDE.

remix1.png

2. In our example, we will use one of the test smart contracts that is already uploaded into the IDE. Open contracts/1_Storage.sol file.

remix2.png

On the right you can see the contract source code. This contract provides two functions. The first (store) allows you to save any number in the contract, and the second (retrieve) allows you to read it.

3. Compile the contract by right-clicking on the file name, then select Compile.

remix3.png

4. When the source code does not contain any errors and compilation is successful, you will see a green success icon.

remix4.png

5. Go to the Deploy tab.

remix5.png

6. Expand the Environment list and select Injected Provider - MetaMask.

remix6.png

7. Now Metamask will ask you for permission to connect to the Remix IDE. Agree to connect.

remix7.pngremix8.png

8. After successfully connecting, you should see your account address and its balance in the marked field.

remix9.png

9. Click Deploy to start deploying your contract. Confirm the suggested gas settings.

remix10.png

10. In the Metamask popup window, change the gas settings by clicking on Site suggested, then select the Market option. Then confirm the transaction.

remix11.pngremix12.pngremix13.png

11. Your contract is now deploying. If you open the Metamask window, you should see the new pending transaction.

remix14.png

12. Once the transaction is confirmed by blockchain, you will see its confirmation and a new item in the Deployed Contracts section. Your contract is deployed.

remix15.png

13. You can use the marked button to copy the address of your new contract to interact with it in the future.

remix16.png

14. Now you can test the contract by calling its functions. Expand the list of contract methods.

remix17.png

15. Let's call the first function (store) to save any number in the contract. Enter random number in the text field next to the store button. Then press the store button.

remix18.png

16. Confirm the transaction in your wallet in the same way as when deploying the contract. Saving data to a smart contract requires a transaction on the blockchain.

17. When the transaction is confirmed, call the second function (retrieve) to read the number stored in the smart contract. Click the retrieve function button. The blockchain will return the value stored in the contract.

remix19.png

Deploying ERC-20 token on BPX mainnet using Remix IDE

  1. Open the Remix IDE. Expand the workspaces menu and select Create.

token1.png

2. Select the OpenZeppelin / ERC20 template.

token2.png

3. Configure your token features.

In the Upgradeability section, you can configure the possibility of updating your token contract in the future. This is an advanced option that we won't cover in the beginner tutorial.

In the Workspace name field, enter the name of your project.

Confirm with the OK button.

token3.png

4. The IDE will generate the token contract source code. Change the contract name, token name and token symbol.

token4.png

token5.png

5. Rename the contract file to match the contract name, in our case TutorialToken.sol.

token6.png

6. Compile and deploy the token contract. We explained how to do it in another tutorial.

token7.png

7. The token contract is already on the blockchain. Now we will mint 100 TTK to our wallet. Expand the contract method named mint. Enter your wallet address in to: field. In the amount: field enter the amount of token you want to mint. Keep in mind that the token has 18 decimal places by default, and the amount is entered in the smallest units. So enter 100 followed by 18 zeros to mint 100 TTK.

token8.png

8. Click transact and confirm the transaction in your wallet. Wait for its confirmation by the blockchain.

token9.png

9. Copy your token's contract address. You will always need it to add a token to the wallet.

token10.png

10. Now open Metamask, go to Assets and select Import tokens.

token11.png

11. Paste the token contract address. The other fields will be automatically read from the blockchain. Click Add custom token and Import tokens.

token12.pngtoken13.png

12. Done. The token is visible in your wallet. You can send and receive it to other addresses just like a native BPX token. Keep in mind that your wallet is the smart contract owner and only this wallet can call mint function in the future to mint new token units or burn function to burn them.

token14.png