Support sending SOL

This commit is contained in:
Nishad 2020-08-06 02:11:20 +08:00 committed by Gary Wang
parent 5ef4729ea9
commit a515840db1
1 changed files with 15 additions and 1 deletions

View File

@ -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);