Developers Forum for XinFin XDC Network

Cover image for Deploying Vyper Smart Contracts (SendXDC) on XDC Apothem Network
Vinn
Vinn

Posted on

Deploying Vyper Smart Contracts (SendXDC) on XDC Apothem Network

XDC Network is a high-speed blockchain that offers a secure and scalable platform for developers to build decentralized applications (dApps). It supports Solidity as well as Vyper smart contract languages. In this article, we’ll take a closer look at how to deploy Vyper smart contracts on the XDC Network.

Before we begin, make sure you have the following prerequisites:

  • Some XDC: You’ll need some XDC to deploy your smart contracts on the XDC Network. You can get XDC from exchanges like Bitrue, KuCoin, or ProBit.
  • Vyper: Vyper is a Pythonic smart contract language that is designed to be simple, secure, and auditable. You can install Vyper using pip by running the following command:
pip install vyper
Enter fullscreen mode Exit fullscreen mode

Refer my article to know “How to deploy a smart contract using Vyper on XDC Network!"

Once you have these prerequisites, you can move on to deploying your Vyper smart contracts on the XDC Network.

The below contract will help to transfer XDC to multiple addresses.

First we need to add a bulk amount of XDC to the contract at the time of deployment.

To deploy a Vyper smart contract on the XDC Network, follow these steps:

Write your smart contract code in Vyper. Here’s an example of a simple Vyper smart contract: There are two ways to send XDC from a contract, send and raw_call. Here we introduce the simpler function to use, send.

# Receive XDC into this contract
@external
@payable
def __default__():
pass
@external
def sendXDC(to: address, amount: uint256):
# when XDC is sent to a contract it will call
# __default__ inside the receiving contract
# forwards 2300 gas
send(to, amount)
@external
def sendAll(to: address):
send(to, self.balance)
Enter fullscreen mode Exit fullscreen mode

Here’s a breakdown of the code:

The default function is a fallback function that is triggered when the contract receives XDC. The function does nothing in this case, as it’s left blank with the pass keyword.

The sendXDC function takes in two parameters — a destination address (to) and an amount of XDC to send (amount). The function then uses the send function to forward the specified amount of XDC to the destination address.

The sendAll function takes in a single parameter — a destination address (to). The function then uses the self.balance property to get the balance of XDC held by the contract, and forwards that entire balance to the specified destination address using the send function.

To run this code on the XDC Apothem Network using Remix, you’ll need to follow these steps:

Step 1: Open the Remix IDE in your web browser and create a new Vyper file with the “SendXDC.vy” extension and Copy — paste the provided code into the file.

Image description

Step 2: To compile this smart contract, visit the “Vyper Compiler” tab, select “Remote Compiler”, and click the “Compile SendXDC.vy” button.

Image description

Once compiled successfully, users can see the green tick on the V shape icon.

  1. Now, Visit “Deploy & Run transactions” tab,
  • Select the environment as “Injected Provider” to connect XDCPay
  • Enter the Value(Bulk amount to send multiple addresses), select “Ether”
  • Click on Deploy button, to deploy the “SendXDC.vy” contract on XDC Apothem Network. Image description

Step 4: Sign the transaction by clicking on the Confirm button of XDCPay.
Image description

Once deployed successfully, you can interact with the contract by calling its functions from the Remix interface. You’ll need to have some XDC in your wallet to test the contract’s functionality.

Image description

Let’s send some XDC to another address by calling sendXDC function:

  • Enter the receiver address
  • Enter the amount with 18 zeros
  • Click on transact button
  • Click on Confirm transaction button of XDCPay

Image description

The same way you can access sendAll function to transfer the XDC to multiple addresses.

Try at your end! For any developer support, post your queries here at XDC.Dev

Important Links related to XDC Network

Discussion (0)