Skip to content

Commit 8c32239

Browse files
Merge pull request #8 from namada-net/feat/nodejs-transparent-transfer-example
feat: nodejs transparent transfer tx example
2 parents e0263a2 + 2b4a4d8 commit 8c32239

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

node/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"homepage": "https://github.com/namada-net/namada-sdkjs-examples#readme",
2121
"dependencies": {
22-
"@namada/sdk-node": "^0.23.0"
22+
"@namada/sdk-node": "^0.23.1",
23+
"bignumber.js": "^9.3.1"
2324
},
2425
"devDependencies": {
2526
"@eslint/js": "^9.33.0",

node/src/index.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Sdk, initSdk } from "@namada/sdk-node";
1+
import BigNumber from "bignumber.js";
2+
import { Sdk, WrapperTxProps, initSdk } from "@namada/sdk-node";
23

34
const initializeSdk = async (): Promise<Sdk> => {
4-
const rpcUrl = "https://rpc.housefire.tududes.com";
5+
const rpcUrl = "https://rpc.mainnet.siuuu.click";
56
const token = "tnam1q9gr66cvu4hrzm0sd5kmlnjje82gs3xlfg3v6nu7";
6-
const maspIndexerUrl = "https://masp.housefire.tududes.com";
7+
const maspIndexerUrl = "https://masp.mainnet.siuuu.click";
78
const dbName = "testDb";
89

910
const sdk = await initSdk({ rpcUrl, token, maspIndexerUrl, dbName });
@@ -17,6 +18,40 @@ const app = async () => {
1718
console.log("Native token:", nativeToken);
1819
const validators = await sdk.rpc.queryAllValidators();
1920
console.log("Validators:", validators);
21+
await broadcastTransferTx(sdk);
2022
};
2123

2224
app().then(() => console.log("IT WORKED!"));
25+
26+
const broadcastTransferTx = async (sdk: Sdk) => {
27+
const wrapperTxProps: WrapperTxProps = {
28+
token: "tnam1q9gr66cvu4hrzm0sd5kmlnjje82gs3xlfg3v6nu7",
29+
feeAmount: BigNumber("0.000001"),
30+
gasLimit: BigNumber("62500"),
31+
chainId: "namada.5f5de2dd1b88cba30586420",
32+
publicKey:
33+
"tpknam1qpam035talr4f8qgltku73dl6zr3t6p22t39w74qatpcecfxgkhgw8tktev", // replace with actual public key
34+
};
35+
const transferProps = {
36+
data: [
37+
{
38+
source: "tnam1qrxsru5rdu4he400xny6p779fcw7xuftsgjnmzup", // replace with actual source address
39+
target: "tnam1qpqfsmj2quxnakfq0rn8y2tjcvtz26f8pyw4fq98", // replace with actual target address
40+
token: "tnam1q9gr66cvu4hrzm0sd5kmlnjje82gs3xlfg3v6nu7",
41+
amount: BigNumber("0.00001"),
42+
},
43+
],
44+
};
45+
const tx = await sdk
46+
.getTx()
47+
.buildTransparentTransfer(wrapperTxProps, transferProps);
48+
console.log("Built Tx:", tx);
49+
const signedTx = await sdk.getSigning().sign(
50+
tx,
51+
"4d4c31e159acffa2ab5983d953f56ef4d9375538eb7f030cff538dd58e197097", // replace with actual private key
52+
);
53+
console.log("Signed Tx:", signedTx);
54+
console.log("Broadcasting Tx..., it might take a while");
55+
const response = await sdk.getRpc().broadcastTx(signedTx);
56+
console.log("Broadcast Response:", response);
57+
};

0 commit comments

Comments
 (0)