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

Omnichain template: add a task to call the contract from Bitcoin #50

Open
fadeev opened this issue Sep 14, 2023 · 0 comments
Open

Omnichain template: add a task to call the contract from Bitcoin #50

fadeev opened this issue Sep 14, 2023 · 0 comments

Comments

@fadeev
Copy link
Member

fadeev commented Sep 14, 2023

Either modify the interact task or introduce a new one that will allow calling the contract from Bitcoin.

This will require making sure that the logic behind send-btc can be called programmatically from the template.

toolkit/tasks/sendBTC.ts

Lines 101 to 144 in d7b6c52

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const TESTNET = bitcoin.networks.testnet;
const API = getEndpoints("blockcypher", "btc_testnet")[0].url;
const pk = process.env.PRIVATE_KEY as any;
const ECPair = ECPairFactory(ecc);
const key = ECPair.fromPrivateKey(Buffer.from(pk, "hex"), {
network: TESTNET,
});
const { address } = bitcoin.payments.p2wpkh({
network: TESTNET,
pubkey: key.publicKey,
});
if (address === undefined) throw new Error("Address is undefined");
const utxos = await fetchUtxos(address);
const tx = await makeTransaction(
args.recipient,
key,
parseFloat(args.amount) * 100000000,
utxos,
address,
args.memo
);
const decoded = JSON.stringify(await decodeTransaction(tx), null, 2);
console.log(`\nTransaction:\n\n${tx}\n`);
console.log(`Decoded transaction:\n\n${decoded}\n`);
await confirm(
{
message: `Send ${parseFloat(args.amount)} tBTC to ${args.recipient}?`,
},
{ clearPromptOnDone: true }
);
const p1 = await fetch(`${API}/txs/push`, {
body: JSON.stringify({ tx }),
method: "POST",
});
const data = await p1.json();
const txhash = data?.tx?.hash;
console.log(`Transaction hash: ${txhash}`);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant