Created
October 21, 2020 08:06
-
-
Save viraj124/7ddc85d50c5117eda2a9bea88a6afd55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
import { QueryParams } from 'routing-controllers'; | |
import { Service } from 'typedi'; | |
import { ApiPromise, WsProvider } from '@polkadot/api'; | |
import { Keyring } from '@polkadot/keyring'; | |
import { StakingOperatioQuery } from '../controllers/requests/StakingQuery'; | |
@Service() | |
export class StafiService { | |
public async operations( | |
@QueryParams() query: StakingOperatioQuery | |
): Promise<object> { | |
try { | |
// Initialise the provider to connect to the local node | |
const provider = new WsProvider('wss://scan-rpc.stafi.io'); | |
// Create the API and wait until ready | |
const api = await ApiPromise.create({ provider }); | |
const Addr = '32LLpDg3xpTHWGa4o5w4pbMkgfHcXDNH8sooJbcb7G88LwSN' | |
const FIS = 1 | |
const keyring = new Keyring({ type: 'sr25519' }); | |
const alice = keyring.addFromMnemonic("Mnemonic"); // also tried addFromUri with passing Mnemonic | |
const transfer = await api.tx.staking.bond(Addr, FIS, 'Staked'); | |
await transfer.signAndSend(alice); | |
} catch (err) { | |
console.log(err) | |
return { err }; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment