> For the complete documentation index, see [llms.txt](https://vinu.gitbook.io/vinuchain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vinu.gitbook.io/vinuchain/technical-docs/web3-methods/transfer.js.md).

# transfer.js

```
var Web3 = require('web3');
const ethers = require('ethers');

const { MAINNET_RPC, TESTNET_RPC } = require('../constants');

var web3 = new Web3(MAINNET_RPC);

const transfer = async () => {
  let address = process.env.FROM_ADDRESS;
  let balance = await web3.eth.getBalance(address);

  console.log(`Get balance of ${address} in Wei: `, balance);

  console.log(
    `Get balance of ${address} in Ether: `,
    web3.utils.fromWei(balance, 'ether')
  );

  const gasPrice = await web3.eth.getGasPrice();

  const transaction = {
    to: process.env.TO_ADDRESS,
    value: 100000000000000000,
    gas: 21000,
    gasPrice
  };

  const signedTx = await web3.eth.accounts.signTransaction(
    transaction,
    process.env.PRIVATE_KEY
  );

  web3.eth.sendSignedTransaction(
    signedTx.rawTransaction,
    function (error, hash) {
      if (!error) {
        console.log(`🎉 The hash of your transaction is: https://mainnet.vinuscan.com/tx/${hash}`);
      } else {
        console.log(
          '❗Something went wrong while submitting your transaction:',
          error
        );
      }
    }
  );
};

const transferWithParams = async (mainnet) => {
  const { FROM_ADDRESS: address, TO_ADDRESS, PRIVATE_KEY } = process.env;
  let RPC, chainId;
  let URL;

  if (mainnet) {
    RPC = MAINNET_RPC;
    chainId = 207;
    URL = 'https://mainnet.vinuscan.com/tx/';
  } else {
    RPC = TESTNET_RPC;
    chainId = 206;
    URL = 'https://testnet.vinuscan.com/tx/';
  }

  var testWeb3 = new Web3(RPC);

  var nonceVal = await testWeb3.eth.getTransactionCount(address);

  // Change maxFeePerGas and maxPriorityFeePerGas as per the current gas prices
  var transaction = {
    to: TO_ADDRESS,
    from: address,
    nonce: nonceVal,
    value: testWeb3.utils.toHex(testWeb3.utils.toWei('0.1', 'ether')),
    gas: testWeb3.utils.toHex(21000),
    maxFeePerGas: '0x174876E800', // 100 Gwei 
    maxPriorityFeePerGas: '0xBA43B7400', // 50 Gwei
    chainId
  };

  const signedTx = await testWeb3.eth.accounts.signTransaction(
    transaction,
    PRIVATE_KEY
  );

  testWeb3.eth.sendSignedTransaction(
    signedTx.rawTransaction,
    function (error, hash) {
      if (!error) {
        console.log(`🎉 The hash of your transaction is: ${URL}${hash}`);
      } else {
        console.log(
          '❗Something went wrong while submitting your transaction:',
          error
        );
      }
    }
  );
};

module.exports = { transfer, transferWithParams };
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vinu.gitbook.io/vinuchain/technical-docs/web3-methods/transfer.js.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
