From a515840db127e6674bd963bd9b7512ae3f73fce9 Mon Sep 17 00:00:00 2001 From: Nishad Date: Thu, 6 Aug 2020 02:11:20 +0800 Subject: [PATCH] Support sending SOL --- src/utils/wallet.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils/wallet.js b/src/utils/wallet.js index 7f2ea9d..eeca7ba 100644 --- a/src/utils/wallet.js +++ b/src/utils/wallet.js @@ -1,6 +1,6 @@ import React, { useContext, useMemo } from 'react'; import * as bip32 from 'bip32'; -import { Account } from '@solana/web3.js'; +import { Account, SystemProgram } from '@solana/web3.js'; import nacl from 'tweetnacl'; import { setInitialAccountInfo, @@ -69,6 +69,9 @@ export class Wallet { }; transferToken = async (source, destination, amount) => { + if (source.equals(this.publicKey)) { + return this.transferSol(destination, amount); + } return await transferTokens({ connection: this.connection, owner: this.account, @@ -77,6 +80,17 @@ export class Wallet { amount, }); }; + + transferSol = async (destination, amount) => { + return await this.connection.sendTransaction( + SystemProgram.transfer({ + fromPubkey: this.publicKey, + toPubkey: destination, + lamports: amount, + }), + [this.account], + ); + }; } const WalletContext = React.createContext(null);