Skip to content

Commit

Permalink
Thorchain transfer example (#1284)
Browse files Browse the repository at this point in the history
* Thorchain transfer example

* tsconfig
  • Loading branch information
0xp3gasus authored Oct 3, 2024
1 parent 5fb7282 commit 23975f9
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/thorchain/.codesandbox/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// These tasks will run in order when initializing your CodeSandbox project.
"setupTasks": [
{
"name": "Install Dependencies",
"command": "yarn install"
}
]
}
4 changes: 4 additions & 0 deletions examples/thorchain/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Devcontainer",
"image": "ghcr.io/codesandbox/devcontainers/typescript-node:latest"
}
2 changes: 2 additions & 0 deletions examples/thorchain/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# xchainjs-thorchain

15 changes: 15 additions & 0 deletions examples/thorchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Thorchain

Thorchain examples to show different use cases using its client

## Examples

### Transactions

#### Make transaction

Check out how you should make a Thorchain native asset transaction in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/thorchain/transaction-transfer.ts) or run it as

```sh
yarn transfer phrase recipient amount
```
21 changes: 21 additions & 0 deletions examples/thorchain/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "xchainjs-thorchain",
"private": true,
"version": "0.0.1",
"scripts": {
"transfer": "npx ts-node transaction-transfer.ts",
"build": "tsc --noEmit"
},
"description": "Examples using Thorchain client",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@xchainjs/xchain-thorchain": "workspace:*",
"@xchainjs/xchain-util": "workspace:*"
},
"devDependencies": {
"@types/node": "20.11.28",
"ts-node": "10.9.2",
"typescript": "^5.0.4"
}
}
27 changes: 27 additions & 0 deletions examples/thorchain/transaction-transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Client, defaultClientConfig } from '@xchainjs/xchain-thorchain'
import { assetAmount, assetToBase } from '@xchainjs/xchain-util'

const main = async () => {
const phrase = `${process.argv[2]}`
const recipient = `${process.argv[3]}`
const amount = assetAmount(`${process.argv[4]}`, 8)

const client = new Client({
...defaultClientConfig,
phrase,
})

const hash = await client.transfer({
recipient,
amount: assetToBase(amount),
})

console.log({
hash,
url: client.getExplorerTxUrl(hash),
})
}

main()
.then(() => process.exit(0))
.catch((err) => console.error(err))
15 changes: 15 additions & 0 deletions examples/thorchain/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noEmitOnError": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": [
"es6",
"dom",
"es2016",
"es2017"
]
}
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14085,6 +14085,18 @@ __metadata:
languageName: unknown
linkType: soft

"xchainjs-thorchain@workspace:examples/thorchain":
version: 0.0.0-use.local
resolution: "xchainjs-thorchain@workspace:examples/thorchain"
dependencies:
"@types/node": "npm:20.11.28"
"@xchainjs/xchain-thorchain": "workspace:*"
"@xchainjs/xchain-util": "workspace:*"
ts-node: "npm:10.9.2"
typescript: "npm:^5.0.4"
languageName: unknown
linkType: soft

"xchainjs-wallet@workspace:examples/wallet":
version: 0.0.0-use.local
resolution: "xchainjs-wallet@workspace:examples/wallet"
Expand Down

0 comments on commit 23975f9

Please sign in to comment.