query information about a block by blockHash
{string} A string representing the hash (32 bytes) of a block.
Optional
transactionDetails: boolean{boolean} If set to true, returns the full transaction objects, if false returns only the hashes of the transactions.
query information about a block by hexBlockNumber
{string} A hexadecimal block number, or one of the string tags latest, earliest, pending, safe, or finalized.
Optional
transactionDetails: boolean{boolean} If set to true, returns the full transaction objects, if false returns only the hashes of the transactions.
Broadcast a transaction
{string} the string of the signed transaction object
//
// This is a complete example of how to send a transaction using .signTransaction and .broadcastTransaction
//
// switch chain/network to Eth.Sepolia
setCurrentChain( 11155111 );
// try to create a wallet from a private key
const publicWalletPrivateKey = '0xc7f832621897e67d973f0f1c497198ed1b89a138f2fe3cc6ce6a59cd3fb7cd4c';
const walletObj = new WalletFactory().createWalletFromPrivateKey( publicWalletPrivateKey );
//
// send translation from [oneKey wallet 1] to [oneKey wallet 2]
//
const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
const sendValue1 : string = '0.001124'; // in ETH
let singedTx : string = await new WalletTransaction().signTransaction( walletObj, payeeAddress, sendValue1, -1, 100 );
let broadcastResponse : TransactionResponse | undefined = undefined;
try
{
broadcastResponse = await new WalletTransaction().broadcastTransaction( singedTx );
}
catch ( err : any )
{
const minimumNeededGas : TransactionMinimumNeededGas | null = new WalletTransaction().extractMinimumNeededGasLimit( err );
if ( minimumNeededGas )
{
//
// The reason for the abnormal transaction is that the gas fee is too low,
// and we have successfully extracted the lowest gas fee reminder from the error
//
// Now, let’s try to send this transaction again with more gas fee.
//
singedTx = await new WalletTransaction().signTransaction( walletObj, payeeAddress, sendValue1, -1, minimumNeededGas.minimum + 100 );
broadcastResponse = await new WalletTransaction().broadcastTransaction( singedTx );
}
else
{
// just throw the error again
throw err;
}
}
Send a derivative token
{string} contract address
{WalletEntityBaseItem} wallet object
{string} recipient's wallet address
{string} value string in ETH. for example: 0.01
Optional
decimals: number = 18{number} decimals
Optional
nonce: number = -1{number} nonce value
Optional
gasLimit: number = 0{number} gas limit value, in wei
//
// This is a complete example of how to send a transaction
//
// switch chain/network to Eth.Sepolia
setCurrentChain( 11155111 );
// try to create a wallet from a private key
const publicWalletPrivateKey = '0xc7f832621897e67d973f0f1c497198ed1b89a138f2fe3cc6ce6a59cd3fb7cd4c';
const walletObj = new WalletFactory().createWalletFromPrivateKey( publicWalletPrivateKey );
//
// send translation from [oneKey wallet 1] to [oneKey wallet 2]
//
const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
const usdtContractAddress = '0x271B34781c76fB06bfc54eD9cfE7c817d89f7759'; // USDT contract address on sepolia
const sendValueUsdt : string = '1.1'; // in USDT
let broadcastResponse : TransactionResponse | undefined = undefined;
try
{
broadcastResponse = await new WalletTransaction().sendContractToken
(
usdtContractAddress,
walletObj,
payeeAddress,
sendValueUsdt,
6
);
}
catch ( err : any )
{
const minimumNeededGas : TransactionMinimumNeededGas | null = new WalletTransaction().extractMinimumNeededGasLimit( err );
if ( minimumNeededGas )
{
//
// The reason for the abnormal transaction is that the gas fee is too low,
// and we have successfully extracted the lowest gas fee reminder from the error
//
// Now, let’s try to send this transaction again with more gas fee.
//
broadcastResponse = await new WalletTransaction().sendContractToken
(
usdtContractAddress,
walletObj,
payeeAddress,
sendValueUsdt,
6,
-1,
minimumNeededGas.minimum + 100
);
}
else
{
// just throw the error again
throw err;
}
}
send a native token
{WalletEntityBaseItem} wallet object
{string} recipient's wallet address
{string} value in ETH. for example: '0.2' ETH
Optional
nonce: number = -1{number} nonce value
Optional
gasLimit: number = 0{number} gas limit value, in wei.
//
// This is a complete example of how to send a native token using .sendToken
//
// switch chain/network to Eth.Sepolia
setCurrentChain( 11155111 );
// try to create a wallet from a private key
const publicWalletPrivateKey = '0xc7f832621897e67d973f0f1c497198ed1b89a138f2fe3cc6ce6a59cd3fb7cd4c';
const walletObj = new WalletFactory().createWalletFromPrivateKey( publicWalletPrivateKey );
//
// send translation from [oneKey wallet 1] to [oneKey wallet 2]
//
const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
const sendValue2 : string = '0.0020010'; // in ETH
let broadcastResponse : TransactionResponse | undefined = undefined;
try
{
const nonce = await new WalletTransaction().queryNonce( walletObj.address );
const estimatedGas = await new WalletTransaction().estimateEthGasLimitByToAddress( payeeAddress );
broadcastResponse = await new WalletTransaction().sendToken( walletObj, payeeAddress, sendValue2, nonce, estimatedGas );
}
catch ( err : any )
{
const minimumNeededGas : TransactionMinimumNeededGas | null = new WalletTransaction().extractMinimumNeededGasLimit( err );
if ( minimumNeededGas )
{
//
// The reason for the abnormal transaction is that the gas fee is too low,
// and we have successfully extracted the lowest gas fee reminder from the error
//
// Now, let’s try to send this transaction again with more gas fee.
//
broadcastResponse = await new WalletTransaction().sendToken( walletObj, payeeAddress, sendValue2, -1, minimumNeededGas.minimum + 100 );
}
else
{
// just throw the error again
throw err;
}
}
sign a transaction of sending native token, before it will be broadcast
{WalletEntityBaseItem}
{string} recipient's wallet address
{string} ETH quantity, unit ETH, for example: "0.001" ETH
Optional
nonce: number = -1{number} The nonce is very important. We can query the current nonce through the Infura API.
Optional
gasLimit: number = 0{number} in wei. The gasLimit for sending ETH is fixed at 21,000. Transactions calling other contracts need to estimate the gasLimit in advance.
estimate gas limit by transaction request object
//
// estimate gas limit by transaction request object
//
const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
const transactionRequest : TransactionRequest = {
to : payeeAddress,
};
const gasLimit = await new WalletTransaction().estimateEthGasLimit( transactionRequest );
//
// should return:
// gasLimit : 21000
//
{TransactionRequest} transaction request object
gas limit in wei.
estimate gas limit by recipient's wallet address
//
// estimate gas limit by transaction request object
//
const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
const gasLimit = await new WalletTransaction().estimateEthGasLimitByToAddress( payeeAddress );
//
// should return:
// gasLimit : 21000
//
{AddressLike} recipient's wallet address
gas limit in wei.
extract Minimum Needed Gas Limit from error
{any} error object
Query the details of a transaction
{string} transaction hash value
Query all transaction history of a wallet
{string} wallet address
Optional
queryOptions: TransactionHistoryQueryOptions{TransactionHistoryQueryOptions}
Optional
fetchOptions: FetchListOptions{FetchListOptions} fetch options
Query the transactions of a wallet by fromAddress
{string} wallet address
Optional
options: FetchListOptions{FetchListOptions} fetch options
Query the transactions of a wallet by toAddress
{string} wallet address
Optional
options: FetchListOptions{FetchListOptions} fetch options
Please configure chain/network before using this class.