Skip to content

Commit

Permalink
AptosAccount-> SupraAccount and refactored example
Browse files Browse the repository at this point in the history
  • Loading branch information
vpanchal-supra committed Oct 3, 2024
1 parent 5d8a957 commit e4a1efc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/example.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { HexString, AptosAccount } from "./index";
import * as supraSDK from "./index";
import { HexString, SupraAccount, SupraClient } from "./index";

// To run this example, install `ts-node` (e.g. `npm install -g ts-node`), enter the directory
// that contains this file and run `ts-node ./example.ts`.
Expand All @@ -14,12 +13,12 @@ import * as supraSDK from "./index";

// To Create Instance Of Supra Client, But In This Method We Don't Need To Pass ChainId.
// ChainId Will Be Identified At Instance Creation Time By Making RPC Call.
let supraClient = await supraSDK.SupraClient.init(
let supraClient = await SupraClient.init(
// "http://localhost:27001/"
"https://rpc-testnet.supra.com/"
);

let senderAccount = new AptosAccount(
let senderAccount = new SupraAccount(
Buffer.from(
"2b9654793a999d1d487dabbd1b8f194156e15281fa1952af121cc97b27578d89",
"hex"
Expand Down
21 changes: 13 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { TxnBuilderTypes, BCS, HexString, AptosAccount } from "aptos";
import {
TxnBuilderTypes,
BCS,
HexString,
AptosAccount as SupraAccount,
} from "aptos";
import axios, { AxiosResponse } from "axios";
import {
normalizeAddress,
Expand All @@ -22,7 +27,7 @@ import {
import { sha3_256 } from "js-sha3";

export * from "./types";
export { TxnBuilderTypes, BCS, HexString, AptosAccount };
export { TxnBuilderTypes, BCS, HexString, SupraAccount };

/**
* Provides methods for interacting with supra rpc node.
Expand Down Expand Up @@ -692,7 +697,7 @@ export class SupraClient {
}

private signSupraTransaction(
senderAccount: AptosAccount,
senderAccount: SupraAccount,
rawTxn: TxnBuilderTypes.RawTransaction
) {
let preHash = Uint8Array.from(
Expand All @@ -712,7 +717,7 @@ export class SupraClient {
}

private async getSendTxPayload(
senderAccount: AptosAccount,
senderAccount: SupraAccount,
rawTxn: TxnBuilderTypes.RawTransaction
): Promise<SendTxPayload> {
console.log("Sequence Number: ", rawTxn.sequence_number);
Expand Down Expand Up @@ -759,7 +764,7 @@ export class SupraClient {
* @returns `TransactionResponse`
*/
async sendTxUsingSerializedRawTransaction(
senderAccount: AptosAccount,
senderAccount: SupraAccount,
serializedRawTransaction: Uint8Array
): Promise<TransactionResponse> {
let sendTxPayload = await this.getSendTxPayload(
Expand Down Expand Up @@ -861,7 +866,7 @@ export class SupraClient {
* @returns `TransactionResponse`
*/
async transferSupraCoin(
senderAccount: AptosAccount,
senderAccount: SupraAccount,
receiverAccountAddr: HexString,
amount: bigint,
waitForTransactionCompletion: boolean = false
Expand Down Expand Up @@ -909,7 +914,7 @@ export class SupraClient {
* @returns `TransactionResponse`
*/
async transferCoin(
senderAccount: AptosAccount,
senderAccount: SupraAccount,
receiverAccountAddr: HexString,
amount: bigint,
coinType: string,
Expand Down Expand Up @@ -957,7 +962,7 @@ export class SupraClient {
* @returns `TransactionResponse`
*/
async publishPackage(
senderAccount: AptosAccount,
senderAccount: SupraAccount,
packageMetadata: Uint8Array,
modulesCode: Uint8Array[]
): Promise<TransactionResponse> {
Expand Down

0 comments on commit e4a1efc

Please sign in to comment.