Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions node/package-lock.json

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

3 changes: 2 additions & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"homepage": "https://github.com/namada-net/namada-sdkjs-examples#readme",
"dependencies": {
"@namada/sdk-node": "^0.23.0"
"@namada/sdk-node": "^0.23.1",
"bignumber.js": "^9.3.1"
},
"devDependencies": {
"@eslint/js": "^9.33.0",
Expand Down
41 changes: 38 additions & 3 deletions node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Sdk, initSdk } from "@namada/sdk-node";
import BigNumber from "bignumber.js";
import { Sdk, WrapperTxProps, initSdk } from "@namada/sdk-node";

const initializeSdk = async (): Promise<Sdk> => {
const rpcUrl = "https://rpc.housefire.tududes.com";
const rpcUrl = "https://rpc.mainnet.siuuu.click";
const token = "tnam1q9gr66cvu4hrzm0sd5kmlnjje82gs3xlfg3v6nu7";
const maspIndexerUrl = "https://masp.housefire.tududes.com";
const maspIndexerUrl = "https://masp.mainnet.siuuu.click";
const dbName = "testDb";

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

app().then(() => console.log("IT WORKED!"));

const broadcastTransferTx = async (sdk: Sdk) => {
const wrapperTxProps: WrapperTxProps = {
token: "tnam1q9gr66cvu4hrzm0sd5kmlnjje82gs3xlfg3v6nu7",
feeAmount: BigNumber("0.000001"),
gasLimit: BigNumber("62500"),
chainId: "namada.5f5de2dd1b88cba30586420",
publicKey:
"tpknam1qpam035talr4f8qgltku73dl6zr3t6p22t39w74qatpcecfxgkhgw8tktev", // replace with actual public key
};
const transferProps = {
data: [
{
source: "tnam1qrxsru5rdu4he400xny6p779fcw7xuftsgjnmzup", // replace with actual source address
target: "tnam1qpqfsmj2quxnakfq0rn8y2tjcvtz26f8pyw4fq98", // replace with actual target address
token: "tnam1q9gr66cvu4hrzm0sd5kmlnjje82gs3xlfg3v6nu7",
amount: BigNumber("0.00001"),
},
],
};
const tx = await sdk
.getTx()
.buildTransparentTransfer(wrapperTxProps, transferProps);
console.log("Built Tx:", tx);
const signedTx = await sdk.getSigning().sign(
tx,
"4d4c31e159acffa2ab5983d953f56ef4d9375538eb7f030cff538dd58e197097", // replace with actual private key
);
console.log("Signed Tx:", signedTx);
console.log("Broadcasting Tx..., it might take a while");
const response = await sdk.getRpc().broadcastTx(signedTx);
console.log("Broadcast Response:", response);
};