-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add entry and view function examples (#144)
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
templates/boilerplate-template/frontend/entry-functions/transferAPT.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { InputTransactionData } from "@aptos-labs/wallet-adapter-react"; | ||
|
||
export type TransferAPTArguments = { | ||
to: string; // the account address to transfer the APT to | ||
amount: number; // the APT amount to transfer | ||
}; | ||
|
||
export const trasnferAPT = (args: TransferAPTArguments): InputTransactionData => { | ||
const { to, amount } = args; | ||
return { | ||
data: { | ||
function: "0x1::aptos_account::transfer", | ||
functionArguments: [to, amount], | ||
}, | ||
}; | ||
}; |
17 changes: 17 additions & 0 deletions
17
templates/boilerplate-template/frontend/view-functions/accountBalance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { aptosClient } from "@/utils/aptosClient"; | ||
|
||
export type AccountAPTBalanceArguments = { | ||
accountAddress: string; | ||
}; | ||
|
||
export const accountAPTBalance = async (args: AccountAPTBalanceArguments): Promise<number> => { | ||
const { accountAddress } = args; | ||
const balance = await aptosClient().view<[number]>({ | ||
payload: { | ||
function: "0x1::coin::balance", | ||
typeArguments: ["0x1::aptos_coin::AptosCoin"], | ||
functionArguments: [accountAddress], | ||
}, | ||
}); | ||
return balance[0]; | ||
}; |