forked from near/near-api-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unwrap-near.js
29 lines (23 loc) · 908 Bytes
/
unwrap-near.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { connect, keyStores, utils } = require("near-api-js");
const path = require("path");
const homedir = require("os").homedir();
const WRAP_NEAR_CONTRACT_ID = "wrap.near";
const credentialsPath = path.join(homedir, ".near-credentials");
const keyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath);
const config = {
keyStore,
networkId: "mainnet",
nodeUrl: "https://rpc.mainnet.near.org",
};
// Unwrap 1 wNEAR to NEAR
unwrapNear("example.near", "1");
async function unwrapNear(accountId, unwrapAmount) {
const near = await connect(config);
const account = await near.account(accountId);
return account.functionCall({
contractId: WRAP_NEAR_CONTRACT_ID,
methodName: "near_withdraw", // method to withdraw wNEAR for NEAR
args: { amount: utils.format.parseNearAmount(unwrapAmount) },
attachedDeposit: "1", // attach one yoctoNEAR
});
}