import * as encoding from "@walletconnect/encoding" ; import { apiGetAccountNonce , apiGetGasPrices } from "./api" ; import { toWad } from "./utilities" ; export async function getGasPrice ( chainId ) { if ( chainId === "eip155:1" ) return toWad ( "20" , 9 ) . toHexString ( ) ; const gasPrices = await apiGetGasPrices ( ) ; return toWad ( `${ gasPrices . slow . price }` , 9 ) . toHexString ( ) ; } export async function formatTestTransaction ( account ) { const [ namespace , reference , address ] = account . split ( ":" ) ; const chainId = `${ namespace }:${ reference }` ; const _nonce = await apiGetAccountNonce ( address , chainId ) ; const nonce = encoding . sanitizeHex ( encoding . numberToHex ( _nonce ) ) ; const _gasPrice = await getGasPrice ( chainId ) ; const gasPrice = encoding . sanitizeHex ( _gasPrice ) ; const _gasLimit = 21000 ; const gasLimit = encoding . sanitizeHex ( encoding . numberToHex ( _gasLimit ) ) ; const _value = 0 ; const value = encoding . sanitizeHex ( encoding . numberToHex ( _value ) ) ; const tx = { from : address , to : address , data : "0x" , nonce , gasPrice , gasLimit , value } ; return tx ; }