Accounts
Initialization
To use the Accounts
class, you first need to initialize an HttpClient
object with your API base URL and security worker. The security worker is a function that returns the headers to be included in the API requests. In this case, it returns an authorization header with a bearer token.
Methods
broadcastTx(accountName: string, data: BroadcastInput, params: RequestParams = {})
broadcastTx(accountName: string, data: BroadcastInput, params: RequestParams = {})
Broadcasts a raw transaction to the blockchain.
Parameters:
accountName
: The name of the account.data
: An object containing thechainId
andrawTransaction
properties.params
: Optional request parameters.
Returns: A promise that resolves to a
BroadcastTxData
object.Example:
createAccount(data: CreateAccountInput, params: RequestParams = {})
createAccount(data: CreateAccountInput, params: RequestParams = {})
Creates a new Ethereum account.
Parameters:
data
: An optional object containing theprivate_key
property. If not provided, a new private key will be generated.params
: Optional request parameters.
Returns: A promise that resolves to a
CreateAccountData
object.Example:
deleteAccount(accountName: string, params: RequestParams = {})
deleteAccount(accountName: string, params: RequestParams = {})
Deletes an existing Ethereum account.
Parameters:
accountName
: The name of the account to delete.params
: Optional request parameters.
Returns: A promise that resolves to a
DeleteAccountData
object.Example:
deployContract(accountName: string, data: DeployInput, params: RequestParams = {})
deployContract(accountName: string, data: DeployInput, params: RequestParams = {})
Deploys a new smart contract to the blockchain.
Parameters:
accountName
: The name of the account that will deploy the contract.data
: An object containing theabi
,bytecode
,chain_id
, andconstructor_args
properties.params
: Optional request parameters.
Returns: A promise that resolves to a
DeployContractData
object.Example:
encodeData(data: AbiEncodeInput, params: RequestParams = {})
encodeData(data: AbiEncodeInput, params: RequestParams = {})
Encodes data using the ABI of a smart contract.
Parameters:
data
: An object containing theabi
,functionName
, andparams
properties.params
: Optional request parameters.
Returns: A promise that resolves to an
EncodeDataData
object.Example:
estimateGas(accountName: string, data: InputBody, params: RequestParams = {})
estimateGas(accountName: string, data: InputBody, params: RequestParams = {})
Estimates the amount of gas required to execute a transaction.
Parameters:
accountName
: The name of the account that will execute the transaction.data
: An object containing the transaction details.params
: Optional request parameters.
Returns: A promise that resolves to an
EstimateGasData
object.Example:
getAccount(accountName: string, params: RequestParams = {})
getAccount(accountName: string, params: RequestParams = {})
Retrieves information about an Ethereum account.
Parameters:
accountName
: The name of the account.params
: Optional request parameters.
Returns: A promise that resolves to a
GetAccountData
object.Example:
getBalance({ accountName, ...query }: GetBalanceParams, params: RequestParams = {})
getBalance({ accountName, ...query }: GetBalanceParams, params: RequestParams = {})
Retrieves the balance of an Ethereum account.
Parameters:
accountName
: The name of the account.query
: Optional query parameters, includingtoken_address
andtoken_id
.params
: Optional request parameters.
Returns: A promise that resolves to a
GetBalanceData
object.Example:
getNonce(accountName: string, params: RequestParams = {})
getNonce(accountName: string, params: RequestParams = {})
Retrieves the nonce of an Ethereum account.
Parameters:
accountName
: The name of the account.params
: Optional request parameters.
Returns: A promise that resolves to a
GetNonceData
object.Example:
listAccounts(params: RequestParams = {})
listAccounts(params: RequestParams = {})
Retrieves a list of all Ethereum accounts.
Parameters:
params
: Optional request parameters.
Returns: A promise that resolves to a
ListAccountsData
object.Example:
signMessage(accountName: string, data: SignMessage, params: RequestParams = {})
signMessage(accountName: string, data: SignMessage, params: RequestParams = {})
Signs a message using an Ethereum account.
Parameters:
accountName
: The name of the account.data
: An object containing themessage
property.params
: Optional request parameters.
Returns: A promise that resolves to a
SignMessageData
object.Example:
signTransaction(accountName: string, data: InputBody, params: RequestParams = {})
signTransaction(accountName: string, data: InputBody, params: RequestParams = {})
Signs a transaction using an Ethereum account.
Parameters:
accountName
: The name of the account.data
: An object containing the transaction details.params
: Optional request parameters.
Returns: A promise that resolves to a
SignTransactionData
object.Example:
signTypedData(accountName: string, data: SignTypedData, params: RequestParams = {})
signTypedData(accountName: string, data: SignTypedData, params: RequestParams = {})
Signs a typed data message using an Ethereum account.
Parameters:
accountName
: The name of the account.data
: An object containing thedata
property.params
: Optional request parameters.
Returns: A promise that resolves to a
SignTypedDataData
object.Example:
suggestGasPrice({ accountName, ...query }: SuggestGasPriceParams, params: RequestParams = {})
suggestGasPrice({ accountName, ...query }: SuggestGasPriceParams, params: RequestParams = {})
Suggests a gas price for a transaction.
Parameters:
accountName
: The name of the account.query
: Optional query parameters, includingspeed
.params
: Optional request parameters.
Returns: A promise that resolves to a
SuggestGasPriceData
object.Example:
transferEth(accountName: string, data: InputBody, params: RequestParams = {})
transferEth(accountName: string, data: InputBody, params: RequestParams = {})
Transfers ETH from one Ethereum account to another.
Parameters:
accountName
: The name of the source account.data
: An object containing the transaction details.params
: Optional request parameters.
Returns: A promise that resolves to a
TransferEthData
object.Example:
These examples assume that you have already initialized the HttpClient
and Accounts
objects as shown in the provided code snippet. Make sure to replace the placeholders with actual values.
Last updated