Support sending SOL
This commit is contained in:
parent
5ef4729ea9
commit
a515840db1
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue