---
title: "How to Send and Receive HBAR Using Smart Contracts – Part 1: Using the SDK"
id: "15868"
type: "post"
slug: "how-to-send-and-receive-hbar-using-smart-contracts-part-1-using-the-sdk"
published_at: "2022-07-20T20:45:00+00:00"
modified_at: "2025-12-10T05:11:22+00:00"
url: "https://hedera.com/blog/how-to-send-and-receive-hbar-using-smart-contracts-part-1-using-the-sdk/"
markdown_url: "https://hedera.com/blog/how-to-send-and-receive-hbar-using-smart-contracts-part-1-using-the-sdk.md"
excerpt: "Smart contracts on Hedera can hold and exchange value in the form of HBAR, Hedera Token Service (HTS) tokens, and even ERC tokens. This is fundamental for building decentralized applications that rely on contracts in areas like DeFi, ESG, NFT..."
taxonomy_category:
  - "Uncategorized"
taxonomy_post_tag:
  - "technical"
---

[Skip to content](#content)
blog

# How to Send and Receive HBAR Using Smart Contracts – Part 1: Using the SDK

July 20, 2022

![Ed Marquez](https://hedera.com//wp-content/uploads/2025/12/Headshot.jpeg)

Ed Marquez

Head of Developer Relations

Smart contracts on Hedera can hold and exchange value in the form of HBAR, Hedera Token Service (HTS) tokens, and even ERC tokens. This is fundamental for building decentralized applications that rely on contracts in areas like DeFi, ESG, NFT marketplaces, DAOs, and more.

In this tutorial, you will learn how to send and receive HBAR to and from Hedera contracts. At a high level, there are two ways to transfer HBAR to and from a contract on Hedera: the SDKs and Solidity.

Part 1 focuses on using the Hedera SDKs. Read [Part 2](https://hedera.com/blog/how-to-send-and-receive-hbar-using-smart-contracts-part-2-solidity)
 for transferring HBAR to and from contracts using Solidity.

#### **Try It Yourself**

- Get a [Hedera testnet account](https://portal.hedera.com/register)
- Use [this Codesandbox](https://codesandbox.io/s/hedera-example-transfer-hbar2contracts-sdk-2jt9go) to try the example
  - Fork the sandbox
  - Remember to provide your testnet account credentials in the .env file
  - Open a new terminal to execute index.js

- Get the [example code from GitHub](https://github.com/ed-marquez/hedera-smart-contracts/tree/examples/examples/transfer-hbar2contracts-sdk)

#### **Transfer HBAR Using the SDKs**

Here are a few key points about transferring HBAR to and from contracts using the SDKs:

- For most, this is the simplest method as it only involves doing a **[TransferTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/transfer-cryptocurrency)**
- Transferring HBAR to a contract:
  - Does not require having:
    - *payable* contracts or functions
    - *receive()*or *fallback()* functions

  - Keep in mind that if your contract has a *fallback()* function, this approach does not invoke it (so that code won’t execute)

- Transferring HBAR from a contract:
  - The contract sending the HBAR must have an admin key to sign the **[TransferTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/transfer-cryptocurrency)**

#### **Example**

This example has three entities: the operator, Alice, and the contract. Your testnet credentials should be used for the operator variables, which are used to initialize the Hedera client that submits transactions to the network and gets confirmations. Create Alice’s account with an initial balance of 100 HBAR, and then Alice will transfer 10 HBAR to the smart contract using the **[TransferTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/transfer-cryptocurrency)**  
 module in the SDK.

Below is the Solidity code for the contract. You can get the bytecode from Codesandbox, the GitHub repository, or by compiling the code.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 
```

#### 1. Create Accounts

Generate a private key for Alice. Hedera supports [ED25519](https://docs.hedera.com/hedera/sdks-and-apis/sdks/keys/generate-a-new-key-pair#ed25519)
  
 and [ECDSA](https://docs.hedera.com/hedera/sdks-and-apis/sdks/keys/generate-a-new-key-pair#ecdsa-secp256k1_-_)
  
 keys.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
const aliceKey = PrivateKey.generateECDSA();
```

Create Alice’s account with a balance of 100 HBAR. The function ***accountCreatorFcn***  
 simplifies the account creation process and is reusable in case you need to create more accounts in the future. This function uses the **[AccountCreateTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/create-an-account)**  
 module. We’ll use this modular approach throughout the article.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
// Create additional accounts needed
const initialBalance = 100;
const [accStatus, aliceId] = await accountCreatorFcn(aliceKey, initialBalance);
console.log(
	`n- Created Alice's account with initial balance of ${initialBalance} hbar: ${accStatus}`
);
```

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
async function accountCreatorFcn(pvKey, iBal) {
	const response = await new AccountCreateTransaction()
		.setInitialBalance(new Hbar(iBal))
		.setKey(pvKey.publicKey)
		.setAlias(pvKey.publicKey.toEvmAddress())
		.execute(client);
	const receipt = await response.getReceipt(client);
	return [receipt.status, receipt.accountId];
}
```

***Console Output:***

*- Created Alice's account with initial balance of 100 hbar: SUCCESS*

#### **2. Deploy the Contract on Hedera**

The compiled contract bytecode is a binary contained in the variable ***contractBytecode***. The function ***contractCreatorFcn*** uses the **[ContractCreateFlow()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/create-a-smart-contract#contractcreateflow)**  
 module and returns the contract ID and corresponding Solidity address for the contract.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
// Import the compiled contract bytecode
const contractBytecode = fs.readFileSync("transferHbar2Contract_sdk_sol_hbar2Contract.bin");

// Deploy the contract on Hedera
const [contractId, contractAddress] = await contractCreatorFcn(contractBytecode);
console.log(`n- The smart contract ID is: ${contractId}`);
console.log(`- The smart contract ID in Solidity format is: ${contractAddress}`);
```

**[ContractCreateFlow()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/create-a-smart-contract#contractcreateflow)**  
 stores the bytecode and deploys the contract on Hedera. This single call handles for you the operations **[FileCreateTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/file-storage/create-a-file)**, **[FileAppendTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/file-storage/append-to-a-file)**, and **[ContractCreateTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/create-a-smart-contract#contractcreatetransaction)**.

Set a gas value that is enough to execute the transaction; otherwise, you'll get the error CONTRACT_REVERT_EXECUTED.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
async function contractCreatorFcn(contractBytecode) {
	const contractDeployTx = await new ContractCreateFlow()
		.setBytecode(contractBytecode)
		.setGas(100000)
		.execute(client);
	const contractDeployRx = await contractDeployTx.getReceipt(client);
	const contractId = contractDeployRx.contractId;
	const contractAddress = contractId.toSolidityAddress();
	return [contractId, contractAddress];
}
```

***Console Output:***

*- The smart contract ID is: 0.0.47716894*

*- The smart contract ID in Solidity format is: 0000000000000000000000000000000002d81a1e*

#### **3. Transfer HBAR to the Contract**

Transfer 10 HBAR to the contract from Alice’s account using the function ***hbarTransferFcn***.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
// Transfer HBAR to smart contract using TransferTransaction()
const hbarAmount = 10;
const transferRx = await hbarTransferFcn(aliceId, contractId, hbarAmount);
console.log(`n- Transfer ${hbarAmount} HBAR from Alice to contract: ${transferRx.status}`);
```

Use the **[TransferTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/transfer-cryptocurrency)**  
 module to transfer the HBAR. Remember that the account for which the balance is deducted must sign the transfer transaction (Alice in this case).

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
async function hbarTransferFcn(sender, receiver, amount) {
	const transferTx = new TransferTransaction()
		.addHbarTransfer(sender, -amount)
		.addHbarTransfer(receiver, amount)
		.freezeWith(client);
	const transferSign = await transferTx.sign(aliceKey);
	const transferSubmit = await transferSign.execute(client);
	const transferRx = await transferSubmit.getReceipt(client);
	return transferRx;
}
```

***Console Output:***

*- Transfer 10 HBAR from Alice to contract: SUCCESS*

#### **4. Check the Balance of the Contract**

Finally, use the function ***contractBalanceCheckerFcn***to check the HBAR balance of the contract. This function checks the balance in two ways: 1) calling the ***getBalance*** function in the contract via a **[ContractCallQuery()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/call-a-smart-contract-function-1)**, and 2) using the **[ContractInfoQuery()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/get-smart-contract-info)**  
 module of the SDK.

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
// Query the contract balance
const [fromCallQuery, fromInfoQuery] = await contractBalanceCheckerFcn(contractId);
console.log(`n- Contract balance (from getBalance fcn): ${fromCallQuery} tinybars`);
console.log(`- Contract balance (from ContractInfoQuery): ${fromInfoQuery.balance.toString()}`);
```

![code window background](https://hedera.com/wp-content/uploads/2025/12/CodeSnippetBackground-scaled.jpg)

```
async function contractBalanceCheckerFcn(contractId) {
	const contractQueryTx = new ContractCallQuery()
		.setContractId(contractId)
		.setGas(100000)
		.setFunction("getBalance");
	const contractQuerySubmit = await contractQueryTx.execute(client);
	const contractQueryResult = contractQuerySubmit.getUint256(0);

	const cCheck = await new ContractInfoQuery().setContractId(contractId).execute(client);
	return [contractQueryResult, cCheck];
}
```

***Console Output:***

*- Contract balance (from getBalance fcn): 1000000000 tinybars*

*- Contract balance (from ContractInfoQuery): 10 ℏ*

#### **Summary**

Now you know how to send HBAR **to** a contract on Hedera using the **[TransferTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/transfer-cryptocurrency)**  
 module of the SDK.

You can also send HBAR **from** a contract using the SDK. However, the contract sending the HBAR must have an admin key to sign the **[TransferTransaction()](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/transfer-cryptocurrency)**.

For contracts without admin keys, be sure to read [Part 2](https://hedera.com/blog/how-to-send-and-receive-hbar-using-smart-contracts-part-2-solidity)
. There you’ll learn how to transfer HBAR to/from contracts using Solidity.

#### **Continue Learning**

- [Open a Testnet Account](https://portal.hedera.com/register)
- [Try Examples](https://docs.hedera.com/hedera/tutorials) and [Tutorials](https://docs.hedera.com/hedera/tutorials)
- [Join the Developer Discord](http://hedera.com/discord)
- [Read the Learning Center](https://hedera.com/learning)

[Back to Blog](/blog)

discover

See more articles

[View All](/blog)

![Image](https://hedera.com/wp-content/uploads/2026/08/Regulation_Blog-1024x576.png)

August 5, 2026

### Details decide. What digital asset policy did in July 2026

Halfway through 2026, the regulatory picture is coming into focus. Hedera Chief Policy Officer Nilmini Rubin and VP Global Policy Isadora Arredondo break down what moved in June across the

[Read More](https://hedera.com/blog/details-decide-what-digital-asset-policy-did-in-july-2026/)

![Deploy Multichain Dapps](https://hedera.com/wp-content/uploads/2026/07/HH600301_DeployMultichainDapps_Final-1024x576.png)

July 17, 2026

### Deploy Multichain Dapps on Hedera in 60 Seconds with scaffold-hbar

Deploying multichain dapps on Hedera has never been easier! With just one command, you can spin up a fully functional dapp using Next.js, Hardhat or Foundry, and AI agent context…

[Read More](https://hedera.com/blog/deploy-multichain-dapps-on-hedera-in-60-seconds-with-scaffold-hbar/)

![Regulation is finding its form](https://hedera.com/wp-content/uploads/2026/07/Regulation_Blog-1-1024x576.png)

July 13, 2026

### Regulation is finding its form in summer 2026

Halfway through 2026, the regulatory picture is coming into focus. Hedera Chief Policy Officer Nilmini Rubin and VP Global Policy Isadora Arredondo break down what moved in June across the

[Read More](https://hedera.com/blog/regulation-is-finding-its-form-in-summer-2026/)

## Ready to get started?

Discover why Hedera is the trusted institutional-grade network powering the new digital economy.

[Start Building](/start-building)

[Contact](/contact)

We use cookies to deliver the best experience on our website and to analyze traffic. By continuing to use this site, you consent to our cookie policy.

Review our [Privacy Policy](/privacy)
 to understand how Hedera collects and uses information.

Accept All CookiesAccept Necessary Cookies
