Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Latest commit

 

History

History

starkware-provider

starkware-provider npm version

Starkware Provider Library

Getting started

import StarkwareWallet from '@authereum/starkware-wallet'
import StarkwareProvider from '@authereum/starkware-provider'
import * as ethers from 'ethers'

const rpcProvider = new ethers.providers.JsonRpcProvider(
  'https://ropsten.rpc.authereum.com'
)
const starkExAddress = '0x5FedCE831BD3Bdb71F938EC26f984c84f40dB477'
const mnemonic =
  'puzzle number lab sense puzzle escape glove faith strike poem acoustic picture grit struggle know tuna soul indoor thumb dune fit job timber motor'
const starkWallet = new StarkwareWallet(mnemonic, rpcProvider)

const privateKey =
  '0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773'
const signerWallet = new ethers.Wallet(privateKey, rpcProvider)
const starkProvider = new StarkwareProvider(
  starkWallet,
  signerWallet,
  starkExAddress
)

const layer = 'starkex'
const application = 'starkexdvf'
const index = '0'

const starkKey = await starkProvider.account(layer, application, index)
console.log(starkKey) // '0x017e159e246999ee9ce7d1103d5d0d52c468bcb385d202ef362de2f878162c48'

Examples

Enable account:

const accounts = await starkProvider.enable(layer, application, index)

Get stark key:

const starkKey = await starkProvider.account(layer, application, index)

Deposit ETH:

const txHash = await starkProvider.depositEth({
  amount,
  quantum,
  vaultId,
})

Deposit ERC20:

const txHash = await starkProvider.depositErc20({
  amount,
  quantum,
  tokenAddress,
  vaultId,
})

Deposit ERC721:

const txHash = await starkProvider.depositErc721({
  tokenId,
  tokenAddress,
  vaultId,
})

Withdraw ETH:

const txHash = await starkProvider.withdrawEth({
  quantum,
  recipient,
})

Withdraw ERC20:

const txHash = await starkProvider.withdrawErc20({
  tokenAddress,
  quantum,
  recipient,
})

Withdraw ERC721:

const txHash = await starkProvider.withdrawErc721({
  tokenAddress,
  tokenId,
  recipient,
})

Transfer ETH:

const starkSignature = await starkProvider.transferEth({
  vaultId,
  to,
  quantum,
  amount,
  nonce,
  expirationTimestamp,
  condition
}

Transfer ERC20:

const starkSignature = await starkProvider.transferErc20({
  vaultId,
  to,
  tokenAddress,
  quantum,
  amount,
  nonce,
  expirationTimestamp,
  condition
}

Transfer ERC721:

const starkSignature = await starkProvider.transferErc721({
  vaultId,
  to,
  tokenAddress,
  tokenId,
  nonce,
  expirationTimestamp,
  condition
}

Create limit order:

const starkSignature = await starkProvider.createOrder({
  sell: {
    vaultId,
    amount,
    data: {
      quantum
    }
  },
  buy: {
    vaultId,
    amount,
    data: {
      quantum
    }
  },
  nonce,
  expirationTimestamp
}

Send transaction:

const txHash = await starkProvider.sendTransaction(tx)

Making RPC calls:

const response = await starkProvider.send('stark_deposit', {
  asset: {
    type: 'ETH',
    data: {
      quantum,
    },
  },
  amount,
  vaultId,
})

WalletConnect

Example using StarkWare provider on dapp side:

import StarkwareProvider from '@authereum/starkware-provider'
import WalletConnect from 'walletconnect'

const wc = new WalletConnect()
const provider = StarkwareProvider.fromWalletConnect(wc)
await wc.connect()

const starkKey = await provider.account({ layer, application, index })
console.log(starkKey)

const txHash = await provider.registerUser({ ethKey, operatorSignature })
console.log(txHash)

Example using StarkWare provider on the wallet side:

import { providers, Wallet } from 'ethers'
import StarkwareProvider from '@authereum/starkware-provider'
import StarkwareWallet from '@authereum/starkware-wallet'

const rpcProvider = new providers.JsonRpcProvider(rpcUrl)
const starkWallet = new StarkwareWallet(mnemonic, rpcProvider, store)
const signerWallet = new Wallet(privateKey, rpcProvider)
const provider = new StarkwareProvider(
  starkWallet,
  signerWallet,
  contractAddress
)

provider.wc.on('connect', handleConnect)
provider.wc.on('session_request', handleSessionRequest)
provider.wc.on('call_request', handleCallRequest)