Etherspot
These are our V1 docs and will be deprecated soon. Please visit https://etherspot.fyi/introduction to use our new version of the SDK.
  • Welcome to Etherspot
    • Chains, Bridges & DEXes
    • Social Logins
    • Web3 Logins
  • Transaction Kit
    • Introduction
    • Code Sandboxes
    • Quick Start
    • React Hooks
      • useEtherspotAssets()
      • useEtherspotNfts()
      • useEtherspotHistory()
        • getAccountTransactions()
        • getAccountTransaction()
      • useEtherspotTransactions()
        • estimate()
        • send()
      • useEtherspotAddresses()
      • useEtherspotBalances()
    • React Components
      • <EtherspotTransactionKit />
      • <EtherspotBatches />
      • <EtherspotBatch />
      • <EtherspotTransaction />
      • <EtherspotContractTransaction />
      • <EtherspotApprovalTransaction />
      • <EtherspotTokenTransferTransaction />
  • BUIDLER React Component
    • Introduction
    • Installation
    • Integrate React Component
    • Shared Sessions
    • Wallet Connectors
    • Blocks
      • Send
      • Batching Transaction
      • Multicall Transaction
      • Swaps
      • Bridges
      • Custom Contract Interactions
      • Styling
    • Build Your Own Block
      • Cross-chain KLIMA DAO Staking
  • Etherspot SDK Guides
    • Requirements
    • Install Etherspot SDK
    • Bootstrap Etherspot SDK
      • Instantiate Etherspot SDK
    • Events
    • Etherspot Block Explorer
    • Etherspot Playground
    • Social Login using Etherspot SDK
    • Sponsored Transactions
  • Use Cases & Guides
    • Crosschain Streaming
    • Token Swaps
    • Transactions
      • Historical
      • Sending
    • Multi-chain Bridges
      • ERC20 Bridge
      • DAI - xDai Bridge
      • xDai - DAI Bridge
      • Native Token Bridge
    • Custom Contract Interaction
    • Multi-chain Assets
    • Multi-chain Gas Prices
    • Peer-to-Peer Payments
  • Reference
    • Etherspot SDK API Docs
    • Etherspot SDK on Github
    • Etherspot on NPM
    • Etherspot Playground
    • Etherspot Block Explorer
    • Etherspot Architecture
    • EIP-1271
    • Etherspot/Pillar Audit
  • Brand Assets
    • Etherspot Brand Assets
  • Security
    • Security
  • Get in touch
    • ⚒️Discord
    • Twitter
    • Telegram
Powered by GitBook
On this page
  • Before we continue...
  • Getting started
  • Ensure Payment Deposit Address is funded
  • Transfer Funds via Payment Deposit
  • Withdraw Funds from Payment Channel
  • Finished!

Was this helpful?

  1. Use Cases & Guides

Peer-to-Peer Payments

Transfer funds from one user to another without Payment Hubs.

PreviousMulti-chain Gas PricesNextEtherspot Architecture

Last updated 2 years ago

Was this helpful?

Before we continue, please ensure that you have had a look at our Supported Ethereum Chains, followed the steps in and how to . We're assuming that you have completed these steps before going forward.

In this example, we're going to show you how to transfer the funds using Peer-to-Peer Deposits

Before we continue...

We're going to be using two Etherspot SDK instances here:

  • A ropsten Etherspot SDK for our sender user wallet

We will use this instance to send our ETH from.

  • A ropsten Etherspot SDK for our receiver user wallet

We will use this instance to receive our ETH on ropsten chain and ETH to pay the gas fees.

Make sure you've checked out Supported Ethereum Chains before you continue as we also show you the code to instantiate ropsten version of the SDK. Remember to use different private keys or authentication for both SDK instances to get different Ethereum addresses on both Ropsten Testnet.

Getting started

For this guide, we're going to transfer ETH from one wallet to another wallet on the Ropsten network. To achieve this, we're going to send ETH from our p2pPaymentDeposit address linked to the user wallet to the another wallet on the Ropsten network.

We're going to assume that we're working with the following definitions:

/**
* User Wallets
* - Network: Ropsten
* - const senderEtherspotUser
*
* - Network: Ropsten
* - const receiverEtherspotUser
*/

Ensure Payment Deposit Address is funded

For this process to work, we need to make sure that the Payment Deposit have enough liquidity in them to facilitate the transfer to another wallet. We're going to be working with the p2pDepositAddress from our user wallet Etherspot SDKs. We can get this address as follows:

const { p2pDepositAddress } = senderEtherspotUser.state;

The p2pDepositAddress exists purely to provide liquidity for other operations. Your address is unaffected.

Once you have received the Test ETH to the p2pDepositAddress in the senderEtherspotUser instance, we're ready to move on.

Transfer Funds via Payment Deposit

We need to transfer the desired amount of funds from our p2pDepositAddress in the senderEtherspotUser instance to the p2pDepositAddress in the receiverEtherspotUser instance

For this, we need to use the Etherspot SDK function updateP2PPaymentChannel to transfer from one Etherspot SDK to another with the following code:

/**
* We're going to set 1 ETH as amount to be transferred.
*/
const amountToSend = ethers.utils.parseEther('1');

const output = await senderEtherspotUser.updateP2PPaymentChannel({
    recipient: receiverEtherspotUser.state.accountAddress,
    totalAmount: amountToSend, 
}).catch(console.error);

// This is the hash we will use in the next step.
console.log('Hash:', output.hash)

Withdraw Funds from Payment Channel

To be able to withdraw the above amountToSend from the receiver Etherspot SDK, we need to perform a few final steps.

We're now working primarily with the Ropsten Receiver Etherspot SDK.

From the above output we need to get the hash to commit from the receiver SDK. This will allow us to withdraw the amount transferred. This can be done with the following:

/*
* Remember to clear your batch and keep the house clean!
*/
await receiverEtherspotUser.clearGatewayBatch();

/**
* Next, commit the Payment Channel. The 
* batchCommitP2PPaymentChannel takes an object with two
* properties:
* - hash: the previously created Payment channel hash
* - deposit: 
* - - true: the exchange amount is transferred to the p2pDepositAddress.
* - - false: the exchange amount is transferred to the accountAddress
*/
await receiverEtherspotUser.batchCommitP2PPaymentChannel({
  hash: output.hash,
  deposit: true, // See notes above
}).catch(console.error);

/**
* Next, we estimate the cost of the transaction...
*/
await receiverEtherspotUser
 .estimateGatewayBatch();

/**
* And finally we submit this to the ETherspot Gateway.
*/
await receiverEtherspotUser
  .submitGatewayBatch();

Make sure that the receiver wallet has enough gas fees to pay on your p2pPaymentDepositAddress.

We now need to add Test ETH from the . Please follow the instructions on the website to receive Test ETH to the p2pDepositAddress.

Finished!

🎉
🛑
↗️
↘️
⚠️
Install Etherspot SDK
Bootstrap Etherspot SDK
Ropsten Faucet
Ropsten Faucet