Skip to content

Instantly share code, notes, and snippets.

@viraj124
Created October 21, 2020 08:06
Show Gist options
  • Save viraj124/7ddc85d50c5117eda2a9bea88a6afd55 to your computer and use it in GitHub Desktop.
Save viraj124/7ddc85d50c5117eda2a9bea88a6afd55 to your computer and use it in GitHub Desktop.
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