Skip to content

Commit

Permalink
feat(*): migrate to algosdk v3.0.0 (#314)
Browse files Browse the repository at this point in the history
* feat(*): migrate to algosdk v3.0.0

BREAKING CHANGE: Update transaction handling to support algosdk v3.x API
- Transaction properties renamed (from -> sender, firstRound -> firstValid)
- New transaction construction format using type and params objects
- Modified transaction signing and verification logic

- Update all package.json files to use algosdk v3.0.0
- Refactor transaction creation and handling across all wallet implementations
- Update test cases to use new transaction format and API

* fix(examples): update transaction params for algosdk v3

Update transaction parameter names in all example projects to match algosdk v3:
- Rename 'from' to 'sender'
- Rename 'to' to 'receiver'

Affects examples in Next.js, Nuxt, React, Solid, Vue, and vanilla TS
  • Loading branch information
drichar authored Nov 16, 2024
1 parent 9107b30 commit 80a0de0
Show file tree
Hide file tree
Showing 42 changed files with 485 additions and 523 deletions.
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@txnlab/use-wallet-react": "workspace:*",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "^1.4.1",
"next": "14.2.15",
"react": "18.3.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/src/app/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function Connect() {
const suggestedParams = await algodClient.getTransactionParams().do()

const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: activeAddress,
to: activeAddress,
sender: activeAddress,
receiver: activeAddress,
amount: 0,
suggestedParams
})
Expand Down
4 changes: 2 additions & 2 deletions examples/nuxt/components/Connect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const sendTransaction = async (wallet: Wallet) => {
const suggestedParams = await algodClient.value.getTransactionParams().do()
const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: wallet.activeAccount.address,
to: wallet.activeAccount.address,
sender: wallet.activeAccount.address,
receiver: wallet.activeAccount.address,
amount: 0,
suggestedParams
})
Expand Down
2 changes: 1 addition & 1 deletion examples/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@txnlab/use-wallet-vue": "workspace:*",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "^1.4.1",
"nuxt": "3.13.2",
"vue": "3.5.12",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@txnlab/use-wallet-react": "workspace:*",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "^1.4.1",
"react": "18.3.1",
"react-dom": "18.3.1"
Expand Down
4 changes: 2 additions & 2 deletions examples/react-ts/src/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function Connect() {
const suggestedParams = await algodClient.getTransactionParams().do()

const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: activeAddress,
to: activeAddress,
sender: activeAddress,
receiver: activeAddress,
amount: 0,
suggestedParams
})
Expand Down
2 changes: 1 addition & 1 deletion examples/solid-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@txnlab/use-wallet-solid": "workspace:*",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "^1.4.1",
"solid-js": "1.9.2"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/solid-ts/src/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function Connect() {
const suggestedParams = await algodClient().getTransactionParams().do()

const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: sender,
to: sender,
sender: sender,
receiver: sender,
amount: 0,
suggestedParams
})
Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@txnlab/use-wallet": "workspace:*",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "^1.4.1"
}
}
4 changes: 2 additions & 2 deletions examples/vanilla-ts/src/WalletComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class WalletComponent {
const suggestedParams = await this.manager.algodClient.getTransactionParams().do()

const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: activeAddress,
to: activeAddress,
sender: activeAddress,
receiver: activeAddress,
amount: 0,
suggestedParams
})
Expand Down
2 changes: 1 addition & 1 deletion examples/vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@txnlab/use-wallet-vue": "workspace:*",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "^1.4.1",
"vue": "3.5.12"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/vue-ts/src/components/Connect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const sendTransaction = async (wallet: Wallet) => {
const suggestedParams = await algodClient.value.getTransactionParams().do()
const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: wallet.activeAccount.address,
to: wallet.activeAccount.address,
sender: wallet.activeAccount.address,
receiver: wallet.activeAccount.address,
amount: 0,
suggestedParams
})
Expand Down
4 changes: 2 additions & 2 deletions packages/use-wallet-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"devDependencies": {
"@types/react": "18.3.11",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"jsdom": "25.0.1",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand All @@ -57,7 +57,7 @@
"@walletconnect/modal": "^2.7.0",
"@perawallet/connect": "^1.3.5",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "^2.7.0",
"algosdk": "^3.0.0",
"lute-connect": "^1.4.1",
"magic-sdk": "^28.13.0",
"react": "^17.0.0 || ^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/use-wallet-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"devDependencies": {
"@solidjs/testing-library": "0.8.10",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"solid-js": "1.9.2",
"tsup": "8.3.0",
"tsup-preset-solid": "2.2.0",
Expand All @@ -79,7 +79,7 @@
"@perawallet/connect-beta": "^2.0.21",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "^2.7.0",
"algosdk": "^3.0.0",
"lute-connect": "^1.4.1",
"magic-sdk": "^28.13.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/use-wallet-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@txnlab/use-wallet": "workspace:*"
},
"devDependencies": {
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"tsup": "8.3.0",
"typescript": "5.6.3",
"vue": "3.5.12"
Expand All @@ -54,7 +54,7 @@
"@perawallet/connect-beta": "^2.0.21",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "^2.7.0",
"algosdk": "^3.0.0",
"lute-connect": "^1.4.1",
"magic-sdk": "^28.13.0",
"vue": "^3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/use-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@walletconnect/modal-core": "2.7.0",
"@walletconnect/sign-client": "2.17.1",
"@walletconnect/types": "2.17.1",
"algosdk": "2.9.0",
"algosdk": "3.0.0",
"lute-connect": "1.4.1",
"magic-sdk": "28.13.0",
"tsup": "8.3.0",
Expand All @@ -66,7 +66,7 @@
"@perawallet/connect-beta": "^2.0.21",
"@walletconnect/modal": "^2.7.0",
"@walletconnect/sign-client": "^2.17.1",
"algosdk": "^2.7.0",
"algosdk": "^3.0.0",
"lute-connect": "^1.4.1"
},
"peerDependenciesMeta": {
Expand Down
152 changes: 84 additions & 68 deletions packages/use-wallet/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,59 +49,60 @@ describe('compareAccounts', () => {

describe('isSignedTxn', () => {
const transaction = new algosdk.Transaction({
from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
fee: 10,
amount: 847,
firstRound: 51,
lastRound: 61,
genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=',
genesisID: 'testnet-v1.0'
})

const encodedTxn = {
amt: transaction.amount,
fee: transaction.fee,
fv: transaction.firstRound,
lv: transaction.lastRound,
snd: Buffer.from(transaction.from.publicKey),
type: 'pay',
gen: transaction.genesisID,
gh: transaction.genesisHash,
grp: Buffer.from(new Uint8Array(0))
}

const encodedSignedTxn = { txn: encodedTxn, sig: Buffer.from('sig') }
type: algosdk.TransactionType.pay,
sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
suggestedParams: {
fee: 0,
firstValid: 51,
lastValid: 61,
minFee: 1000,
genesisID: 'mainnet-v1.0'
},
paymentParams: {
receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
amount: 847
}
})

const encodedTxn = algosdk.encodeMsgpack(transaction)
const decodedRawTxn = algosdk.msgpackRawDecode(encodedTxn)

const txnObj = { txn: decodedRawTxn, sig: Buffer.from('sig') }

it('should return true if the object is a signed transaction', () => {
expect(isSignedTxn(encodedSignedTxn)).toBe(true)
expect(isSignedTxn(txnObj)).toBe(true)
})

it('should return false if the object is not a signed transaction', () => {
expect(isSignedTxn(encodedTxn)).toBe(false)
expect(isSignedTxn(decodedRawTxn)).toBe(false)
})
})

describe('isTransaction', () => {
const transaction = new algosdk.Transaction({
from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
fee: 10,
amount: 847,
firstRound: 51,
lastRound: 61,
genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=',
genesisID: 'testnet-v1.0'
})

const uInt8Array = transaction.toByte()
type: algosdk.TransactionType.pay,
sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
suggestedParams: {
fee: 0,
firstValid: 51,
lastValid: 61,
minFee: 1000,
genesisID: 'mainnet-v1.0'
},
paymentParams: {
receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
amount: 847
}
})

const encodedTxn = algosdk.encodeMsgpack(transaction)

it('should return true if the item is a Transaction', () => {
expect(isTransaction(transaction)).toBe(true)
})

it('should return false if the item is a Uint8Array', () => {
expect(isTransaction(uInt8Array)).toBe(false)
expect(isTransaction(encodedTxn)).toBe(false)
})

it('should return false if the item is an object that is not a Transaction', () => {
Expand All @@ -113,23 +114,28 @@ describe('isTransaction', () => {
})

it('should return false if the item is an array of Uint8Arrays', () => {
expect(isTransaction([uInt8Array, uInt8Array])).toBe(false)
expect(isTransaction([encodedTxn, encodedTxn])).toBe(false)
})
})

describe('isTransactionArray', () => {
const transaction = new algosdk.Transaction({
from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
fee: 10,
amount: 847,
firstRound: 51,
lastRound: 61,
genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=',
genesisID: 'testnet-v1.0'
})

const uInt8Array = transaction.toByte()
type: algosdk.TransactionType.pay,
sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
suggestedParams: {
fee: 0,
firstValid: 51,
lastValid: 61,
minFee: 1000,
genesisID: 'mainnet-v1.0'
},
paymentParams: {
receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
amount: 847
}
})

const encodedTxn = algosdk.encodeMsgpack(transaction)

it('should return true if the item is an array of transactions', () => {
expect(isTransactionArray([transaction, transaction])).toBe(true)
Expand All @@ -144,39 +150,49 @@ describe('isTransactionArray', () => {
})

it('should return false if the item is a single Uint8Array', () => {
expect(isTransactionArray(uInt8Array)).toBe(false)
expect(isTransactionArray(encodedTxn)).toBe(false)
})

it('should return false if the item is an array of Uint8Arrays', () => {
expect(isTransactionArray([uInt8Array, uInt8Array])).toBe(false)
expect(isTransactionArray([encodedTxn, encodedTxn])).toBe(false)
})

it('should return false if the item is a nested array of Uint8Arrays', () => {
expect(isTransactionArray([[uInt8Array, uInt8Array], [uInt8Array]])).toBe(false)
expect(isTransactionArray([[encodedTxn, encodedTxn], [encodedTxn]])).toBe(false)
})
})

describe('flattenTxnGroup', () => {
const transaction1 = new algosdk.Transaction({
from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
fee: 10,
amount: 847,
firstRound: 51,
lastRound: 61,
genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=',
genesisID: 'testnet-v1.0'
type: algosdk.TransactionType.pay,
sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
suggestedParams: {
fee: 0,
firstValid: 51,
lastValid: 61,
minFee: 1000,
genesisID: 'mainnet-v1.0'
},
paymentParams: {
receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
amount: 847
}
})

const transaction2 = new algosdk.Transaction({
from: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
to: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
fee: 15,
amount: 500,
firstRound: 100,
lastRound: 200,
genesisHash: 'JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI=',
genesisID: 'testnet-v1.0'
type: algosdk.TransactionType.pay,
sender: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
suggestedParams: {
fee: 0,
firstValid: 100,
lastValid: 200,
minFee: 1000,
genesisID: 'mainnet-v1.0'
},
paymentParams: {
receiver: '7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q',
amount: 500
}
})

const nestedTxnGroup = [[transaction1, transaction2], [transaction1]]
Expand Down
Loading

0 comments on commit 80a0de0

Please sign in to comment.