Presently, both the AlgoSigner object and the algorand object coexist and work side-by-side, but there's plans to deprecate the AlgoSigner object in future versions of AlgoSigner.
There is a change in the way to access AlgoSigner methods
if (typeof AlgoSigner !== 'undefined') {
console.log('AlgoSigner object is available.');
} else {
console.log('AlgoSigner object was not found.');
}
if (typeof algorand !== 'undefined') {
console.log('algorand object is available.');
} else {
console.log('algorand object was not found.');
}
code snippet output
The algosdk client setup is not effected by the transition
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const token = { 'X-API-Key': 'YOUR API KEY HERE' };
algodClient = new algosdk.Algodv2(token, algodServer, '');
algodClient.getTransactionParams().do()
.then(d => txnParams = d)
.catch(e => console.error(e));
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const token = { 'X-API-Key': 'YOUR API KEY HERE' };
algodClient = new algosdk.Algodv2(token, algodServer, '');
algodClient.getTransactionParams().do()
.then(d => txnParams = d)
.catch(e => console.error(e));
code snippet output
There is a change in the way you connect to AlgoSigner and retrieve accounts
Additional documentation can be found here
AlgoSigner.connect()
.catch(e => console.error(e));
AlgoSigner.accounts({ ledger: 'TestNet' })
.then(d => accounts = d)
.catch(e => console.error(e));
algorand.enable({
genesisID: 'testnet-v1.0',
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
})
.then(d => accounts = d.accounts)
.catch(e => console.error(e));
code snippet output
There's a difference in the method names, as well as the method response when signing transactions
Method name: The signing method changes from AlgoSigner.signTxn
to algorand.signTxns
.
Method response: The returned signed blobs structure changes from [{ txID, blob }, { txID, blob }, ...]
to [ blob, blob, ... ]
.
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: document.getElementById('from').value,
to: document.getElementById('to').value,
amount: +document.getElementById('amount').value,
note: AlgoSigner.encoding.stringToByteArray(document.getElementById('note').value),
suggestedParams: {...txnParams}
});
// Use the AlgoSigner encoding library to make the transactions base64
let b64EncodedTxn = AlgoSigner.encoding.msgpackToBase64(txn.toByte());
AlgoSigner.signTxn([{txn: b64EncodedTxn}])
.then(d => signedTxs = d)
.catch(e => console.error(e));
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: document.getElementById('from').value,
to: document.getElementById('to').value,
amount: +document.getElementById('amount').value,
note: algorand.encoding.stringToByteArray(document.getElementById('note').value),
suggestedParams: {...txnParams}
});
// Use the AlgoSigner encoding library to make the transactions base64
let b64EncodedTxn = algorand.encoding.msgpackToBase64(txn.toByte());
algorand.signTxns([{txn: b64EncodedTxn}])
.then(d => signedTxs = d)
.catch(e => console.error(e));
code snippet output
There is a change in the way signed transactions are sent to the network.
Method name: The method used changes from AlgoSigner.send
to algorand.postTxns
.
Method parameters: algorand.postTxns
receives an array of signed transactions blobs instead of a single blob. The network is determined by the one selected during the algorand.enable()
step.
Method response: similarly, algorand.postTxns
returned object contains an array of txIDs instead of a single ID. The property inside the returned object name changes from { txId }
to { txIDs }
.
An additional method for signing and posting transactions with a single call is provided in the algorand
object. Additional information can be found in the documentation here.
AlgoSigner.send({
ledger: 'TestNet',
tx: signedTxs[0].blob
})
.then(d => sendResponse = d)
.catch(e => console.error(e));
algorand.postTxns(signedTxs)
.then(d => sendResponse = d)
.catch(e => console.error(e));
code snippet output