Skip to content

Commit

Permalink
feat: Add signTransaction documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mucahit committed May 23, 2022
1 parent 04c38bb commit 1100d0c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ JavaScript SDK for integrating [Pera Wallet](https://perawallet.app) to web appl

[Learn how to integrate with your JavaScript application](#guide)

[Learn how to Sign Transactions](#sign-transaction)

### Example Applications

[Using React Hooks](https://codesandbox.io/s/perawallet-connect-react-demo-ib9tqt?file=/src/App.js)
Expand Down Expand Up @@ -76,6 +78,57 @@ function App() {
}
```

### Sign Transaction

`@perawallet/connect` also allows signing transactions using the Pera Wallet application. Once the `signTransaction` method is triggered if the user is on a mobile browser, the Pera Wallet app will be launched automatically, if the browser blocks the redirection there's also a popup that links to the Pera Wallet app.

`signTransaction` accepts `SignerTransaction[][]` the type can be found [here](./src/util/model/peraWalletModels.ts)

**To see more details & working examples please [visit here](https://codesandbox.io/s/txns-demo-pj3nf2)**

```javascript
// Setting up algosdk client
const algod = new algosdk.Algodv2("", "https://node.testnet.algoexplorerapi.io/", 443);

// Setting up Transactions
const suggestedParams = await algod.getTransactionParams().do();
const optInTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: FROM_ADDRESS,
to: FROM_ADDRESS,
assetIndex: ASSET_ID,
amount: 0,
suggestedParams
});
const optInTxn2 = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: FROM_ADDRESS,
to: FROM_ADDRESS,
assetIndex: ASSET_ID,
amount: 0,
suggestedParams
});

// Mapping `Transaction` to `SignerTransaction[]`
const singleTxnGroups = [{txn: optInTxn, signers: [FROM_ADDRESS]}];
const multipleTxnGroups = [
{txn: optInTxn, signers: [FROM_ADDRESS]},
{txn: optInTxn2, signers: [FROM_ADDRESS]}
];

// Single Transaction
try {
const signedTxn = await peraWallet.signTransaction([singleTxnGroups]);
} catch (error) {
console.log("Couldn't sign Opt-in txns", error);
}

// Group Transaction
try {
const signedTxns = await peraWallet.signTransaction([multipleTxnGroups]);
} catch (error) {
console.log("Couldn't sign Opt-in txns", error);
}
```

### Your app name on Pera Wallet

By default, the connect wallet drawer on Pera Wallet gets the app name from `document.title`.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perawallet/connect",
"version": "0.0.11",
"version": "0.0.12",
"description": "JavaScript SDK for integrating Pera Wallet to web applications.",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit 1100d0c

Please sign in to comment.