Migration Guide
If you are coming from an earlier version 1.x.x
of aptos
, you will need to make the following updates.
Install the SDK
Section titled “Install the SDK”The TypeScript SDK V2 is under a new GitHub repo and with a new package name - @aptos-labs/ts-sdk
npm i @aptos-labs/ts-sdk
SDK usage and query the Aptos chain
Section titled “SDK usage and query the Aptos chain”Remove all <*>Client
modules (i.e AptosClient
, FaucetClient
, CoinClient
, etc.) and replace with an Aptos
entry point class
V1
const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);const aptosClient = new AptosClient(NODE_URL);const indexerClient = new IndexerClient(INDEXER_URL);const tokenClient = new TokenClient(aptosClient);
V2
const aptos = new Aptos();
// make queriesconst fund = await aptos.fundAccount({ accountAddress: "0x123", amount: 100 });const modules = await aptos.getAccountModules({ accountAddress: "0x123" });const tokens = await aptos.getAccountOwnedTokens({ accountAddress: "0x123" });
Configuration class
Section titled “Configuration class”To configure your Aptos
client, you can use an AptosConfig
object.
const aptosConfig = new AptosConfig({ network: Network.DEVNET }); // default to devnetconst aptos = new Aptos(config);
Transaction Builder Flow
Section titled “Transaction Builder Flow”Removed all separate transaction functions in favor of a more simplified and friendlier transaction builder flow
V1
const aptosClient = new AptosClient(NODE_URL);
// bcs serialized arguments payloadconst entryFunctionPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction( TxnBuilderTypes.EntryFunction.natural( "0x1::aptos_account", "transfer", [], [bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(receiver.address()))], ), );// generate a raw transactionconst transaction = await client.generateRawTransaction( sender.address(), entryFunctionPayload,);
// non-serialized arguments payloadconst payload: Gen.TransactionPayload = { type: "entry_function_payload", function: "0x1::aptos_account::transfer", type_arguments: [], arguments: [account2.address().hex(), 100000],};// generate a raw transactionconst transaction = await client.generateTransaction( account1.address(), payload,);
// sign transactionconst signedTransaction = AptosClient.generateBCSTransaction( sender, transaction,);// submit transactionconst txn = await client.submitSignedBCSTransaction(signedTransaction);
V2
const aptos = new Aptos();
// non-serialized arguments transactionconst transaction = await aptos.build.transaction({ sender: alice.accountAddress, data: { function: "0x1::coin::transfer", typeArguments: ["0x1::aptos_coin::AptosCoin"], functionArguments: [bobAddress, 100], },});
// bcs serialized arguments transactionconst transaction = await aptos.build.transaction({ sender: alice.accountAddress, data: { function: "0x1::coin::transfer", typeArguments: [parseTypeTag("0x1::aptos_coin::AptosCoin")], functionArguments: [bobAddress, new U64(100)], },});// sign transactionconst senderAuthenticator = aptos.sign.transaction({ signer: alice, transaction,});// submit transactionconst committedTransaction = await aptos.submit.transaction({ transaction, senderAuthenticator,});
Account
Section titled “Account”Rename AptosAccount
to Account
and use static methods to generate / derive an account
V1
// generate a new account (or key pair) OR derive from private key OR derive from private key and addressconst account = new AptosAccount(); // supports only Legacy Ed25519
// derive account from derivation pathconst account = AptosAccount.fromDerivePath(..)
V2
// generate a new account (or key pair)const account = Account.generate(); // defaults to Legacy Ed25519const account = Account.generate({ scheme: SigningSchemeInput.Secp256k1Ecdsa }); // Single Sender Secp256k1const account = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: false,}); // Single Sender Ed25519
// derive account from private keyconst account = Account.fromPrivateKey({ privateKey });
// derive account from private key and addressconst account = Account.fromPrivateKeyAndAddress({ privateKey, address: accountAddress,});
// derive account from derivation pathconst account = Account.fromDerivationPath({ path, mnemonic, scheme: SigningSchemeInput.Ed25519,});