Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proof of concept: pay with usdt on statemint #648

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"xcm-cross-chain-transfer": "ts-node scripts/xcm-cross-chain-transfer",
"xcm-return-unknown-tokens": "ts-node scripts/xcm-return-unknown-tokens",
"democracy": "ts-node scripts/democracy",
"statemint-usdt-fee": "ts-node scripts/statemint-usdt-fee",
"create-proposal": "ts-node scripts/create-proposal",
"undercollateralized-borrowers": "ts-node scripts/get-undercollateralized-borrowers",
"test": "run-s build test:*",
Expand Down
52 changes: 52 additions & 0 deletions scripts/statemint-usdt-fee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

import { createSubstrateAPI } from "../src/factory";
import { Keyring } from "@polkadot/api";
import { SubmittableExtrinsic } from "@polkadot/api/types";
import { ISubmittableResult } from "@polkadot/types/types";


async function sendTx(
transaction: SubmittableExtrinsic<"promise">,
onlyInBlock?: boolean
): Promise<ISubmittableResult> {
const keyring = new Keyring({ type: "sr25519" });
const account = keyring.addFromUri("//Alice");
const { unsubscribe, result } = await new Promise((resolve, reject) => {
let unsubscribe: () => void;
transaction
.signAndSend(account, { nonce: -1, assetId: 1984 }, (result: ISubmittableResult) => callback({ unsubscribe, result }))
.then((u: () => void) => (unsubscribe = u))
.catch((error) => reject(error));

let foundStatus = false;
// only need to check this if we do want to wait for the success event
function callback(callbackObject: { unsubscribe: () => void; result: ISubmittableResult }): void {
const status = callbackObject.result.status;
foundStatus = foundStatus || (onlyInBlock && status.isInBlock) || status.isFinalized;

if (foundStatus) {
resolve(callbackObject);
}
}
});

if (result.status.isInBlock) {
console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
} else if (result.status.isFinalized) {
console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`);
}
unsubscribe(result);

if (result.dispatchError) {
return Promise.reject();
}
return result;
}

async function main(): Promise<void> {
const api = await createSubstrateAPI("ws://127.0.0.1:8000");
let tx = api.tx.system.remark("test");
await sendTx(tx, true);
}

main();