@polkadot/keyring#createTestKeyring TypeScript Examples

The following examples show how to use @polkadot/keyring#createTestKeyring. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: setup.ts    From squid with GNU General Public License v3.0 6 votes vote down vote up
export async function transfer(api: ApiPromise, from: string, to: string, amount: number): Promise<number> {
    let keyring = createTestKeyring()
    let sender = keyring.getPair(from)

    let blockHash: any = await new Promise((resolve, reject) => {
        let unsub = () => {
            /* dummy */
        }
        api.tx.balances
            .transfer(to, amount)
            .signAndSend(sender, (result) => {
                if (result.isFinalized) {
                    unsub()
                    resolve(result.status.asFinalized)
                    return
                }
                if (result.isError) {
                    unsub()
                    reject(
                        result.dispatchError ||
                        result.internalError ||
                        new Error('Failed to perform transfer')
                    )
                }
            }).then(u => (unsub = u), reject)
    })

    let header: Header = await api.rpc.chain.getHeader(blockHash)
    return header.number.toNumber()
}