Interface.KeybanAccount
A KeybanAccount
represents a user's account in the Keyban system.
It provides methods to interact with the blockchain, including signing messages,
fetching balances, transferring tokens, and estimating transaction costs.
Properties
Property | Type | Description |
---|---|---|
address | `0x${string}` | The blockchain address associated with the account. |
publicKey | `0x${string}` | The public key associated with the account. |
Methods
estimateERC20Transfer()
estimateERC20Transfer(params: EstimateERC20TransferParams): Promise<FeesEstimation>
Estimates the cost of transferring ERC20 tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
params | EstimateERC20TransferParams | The parameters for estimating the ERC20 transfer. |
Returns
Promise
<FeesEstimation
>
- A promise that resolves to a
FeesEstimation
object containing the fee details.
Throws
If there is an issue with estimating the gas or fees.
Example
const handleEstimate = async () => {
// account, recipient, contractAddress, amount, setTransferCost are state variables
try {
const valueInWei = BigInt(Number(amount) * 1e18);
const estimation = await account.estimateTransferERC20({
contractAddress: contractAddress as Address,
to: recipient as Address,
value: valueInWei,
});
setTransferCost(estimation.maxFees.toString());
} catch (err) {
console.log(err);
}
};
estimateNftTransfer()
estimateNftTransfer(params: EstimateNftTransferParams): Promise<FeesEstimation>
Estimates the cost of transferring ERC721 and ERC1155 tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
params | EstimateNftTransferParams | The parameters for estimating the NFT transfer. |
Returns
Promise
<FeesEstimation
>
- A promise that resolves to a
FeesEstimation
object containing the fee details.
Throws
If there is an issue with estimating the gas or fees.
Example
const handleEstimate = async () => {
// account, recipient, contractAddress, tokenId, amount, standard, setTransferCost are state variables
try {
const value = BigInt(amount);
const estimation = await account.estimateNftTransfer({
contractAddress: contractAddress as Address,
tokenId: tokenId as bigint,
to: recipient as Address,
value: value,
standard: standard as 'ERC721' | 'ERC1155',
});
setTransferCost(estimation.maxFees.toString());
} catch (err) {
console.log(err);
}
};
estimateTransfer()
estimateTransfer(to: `0x${string}`): Promise<FeesEstimation>
Estimates the cost of transferring native tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
to | `0x${string}` | The recipient's address. |
Returns
Promise
<FeesEstimation
>
- A promise that resolves to a
FeesEstimation
object containing the fee details.
Throws
If there is an issue with estimating the gas or fees.
signMessage()
signMessage(message: string): Promise<string[] | `0x${string}`>
Signs an Ethereum message.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | The message to be signed. |
Returns
Promise
<string
[] | `0x${string}`
>
- The signed message as a hex string.
Throws
If the message is empty or there is an issue during signing.
transfer()
transfer(
to: `0x${string}`,
value: bigint,
txOptions?: TransactionOptions): Promise<`0x${string}`>
Transfers native tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
to | `0x${string}` | The recipient's address. |
value | bigint | The transfer amount in wei (must be greater than 0). |
txOptions ? | TransactionOptions | Optional transaction options. |
Returns
Promise
<`0x${string}`
>
- A promise that resolves to the transaction hash.
Throws
If the recipient's address is invalid or the transfer amount is invalid.
Example
const handleTransfer = async () => {
// amount, account, recipient, setTransactionHash are state variables
try {
const valueInWei = BigInt(Number(amount) * 1e18);
const txHash = await account.transfer(recipient as Address, valueInWei);
setTransactionHash(txHash);
} catch (err) {
console.log(err);
}
};
transferERC20()
transferERC20(params: TransferERC20Params): Promise<`0x${string}`>
Transfers ERC20 tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
params | TransferERC20Params | The parameters for the ERC20 transfer. |
Returns
Promise
<`0x${string}`
>
- A promise that resolves to the transaction hash.
Throws
If the recipient's address is invalid, the contract address is invalid, or the transfer amount is invalid.
Example
const handleTransfer = async () => {
// amount, account, recipient, contractAddress, setTransactionHash are state variables
try {
const valueInWei = BigInt(Number(amount) * 1e18);
const txHash = await account.transferERC20({
contractAddress: contractAddress as Address,
to: recipient as Address,
value: valueInWei,
});
setTransactionHash(txHash);
} catch (err) {
console.log(err);
}
};
transferNft()
transferNft(params: TransferNftParams): Promise<`0x${string}`>
Transfers ERC721 and ERC1155 tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
params | TransferNftParams | The parameters for the NFT transfer. |
Returns
Promise
<`0x${string}`
>
- A promise that resolves to the transaction hash.
Throws
If the recipient's address is invalid, the contract address is invalid, the transfer amount is invalid, or the token standard is invalid.
Example
const handleTransfer = async () => {
// account, recipient, contractAddress, tokenId, amount, standard, setTransactionHash are state variables
try {
const value = BigInt(amount);
const txHash = await account.transferNft({
contractAddress: contractAddress as Address,
tokenId: tokenId as bigint,
to: recipient as Address,
value: value,
standard: standard as 'ERC721' | 'ERC1155',
});
setTransactionHash(txHash);
} catch (err) {
console.log(err);
}
};