Class.KeybanAccount
The KeybanAccount
class 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.
Implements
Properties
Property | Type | Description |
---|---|---|
address | `0x${string}` | The blockchain address associated with the account. |
publicKey | `0x${string}` | The public key associated with the account. |
sub | string | Represents the unique identifier of the client, extracted from the JWT (JSON Web Token). |
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);
}
};
Implementation of
KeybanAccount.estimateERC20Transfer
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);
}
};
Implementation of
KeybanAccount.estimateNftTransfer
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.
Implementation of
KeybanAccount.estimateTransfer
getBalance()
getBalance(): Promise<string>
Retrieves the balance of the account associated with the current address.
Returns
Promise
<string
>
A promise that resolves to the balance of the account.
Implementation of
KeybanAccount.getBalance
getNft()
getNft(tokenAddress: `0x${string}`, tokenId: string): Promise<{
balance: string;
id: string;
nft: null | {
collection: null | {
decimals: null | number;
iconUrl: null | string;
id: string;
name: null | string;
symbol: null | string;
type: string;
};
id: string;
metadata: any;
tokenId: string;
};
}>
Retrieves the account ERC721 and ERC1155 token balances.
Parameters
Parameter | Type | Description |
---|---|---|
tokenAddress | `0x${string}` | The address of the token contract. |
tokenId | string | The ID of the token. |
Returns
Promise
<{
balance
: string
;
id
: string
;
nft
: null
| {
collection
: null
| {
decimals
: null
| number
;
iconUrl
: null
| string
;
id
: string
;
name
: null
| string
;
symbol
: null
| string
;
type
: string
;
};
id
: string
;
metadata
: any
;
tokenId
: string
;
};
}>
A promise that resolves to the account's ERC721 and ERC1155 tokens.
Name | Type |
---|---|
balance | string |
id | string |
nft | null | { collection : null | { decimals : null | number ; iconUrl : null | string ; id : string ; name : null | string ; symbol : null | string ; type : string ; }; id : string ; metadata : any ; tokenId : string ; } |
Implementation of
KeybanAccount.getNft
getNfts()
getNfts(): Promise<null | {
edges: {
cursor: null | string;
node: null | {
balance: string;
id: string;
nft: null | {
collection: null | {
decimals: ...;
iconUrl: ...;
id: ...;
name: ...;
symbol: ...;
type: ...;
};
id: string;
metadata: any;
tokenId: string;
};
};
}[];
pageInfo: {
endCursor: null | string;
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: null | string;
};
totalCount: number;
}>
Retrieves the account ERC721 and ERC1155 tokens.
Returns
Promise
<null
| {
edges
: {
cursor
: null
| string
;
node
: null
| {
balance
: string
;
id
: string
;
nft
: null
| {
collection
: null
| {
decimals
: ...;
iconUrl
: ...;
id
: ...;
name
: ...;
symbol
: ...;
type
: ...;
};
id
: string
;
metadata
: any
;
tokenId
: string
;
};
};
}[];
pageInfo
: {
endCursor
: null
| string
;
hasNextPage
: boolean
;
hasPreviousPage
: boolean
;
startCursor
: null
| string
;
};
totalCount
: number
;
}>
A promise that resolves to the account's ERC721 and ERC1155 tokens.
Implementation of
KeybanAccount.getNfts
getTokenBalances()
getTokenBalances(): Promise<null | {
edges: {
cursor: null | string;
node: null | {
balance: string;
id: string;
token: null | {
decimals: null | number;
iconUrl: null | string;
id: string;
name: null | string;
symbol: null | string;
type: string;
};
};
}[];
pageInfo: {
endCursor: null | string;
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: null | string;
};
totalCount: number;
}>
Retrieves the token balances for the current account.
Returns
Promise
<null
| {
edges
: {
cursor
: null
| string
;
node
: null
| {
balance
: string
;
id
: string
;
token
: null
| {
decimals
: null
| number
;
iconUrl
: null
| string
;
id
: string
;
name
: null
| string
;
symbol
: null
| string
;
type
: string
;
};
};
}[];
pageInfo
: {
endCursor
: null
| string
;
hasNextPage
: boolean
;
hasPreviousPage
: boolean
;
startCursor
: null
| string
;
};
totalCount
: number
;
}>
A promise that resolves to the token balances of the account.
Implementation of
KeybanAccount.getTokenBalances
getTransferHistory()
getTransferHistory(): Promise<null | {
edges: {
cursor: null | string;
node: null | {
decimals: null | number;
from: null | {
id: string;
};
id: string;
nft: null | {
collection: null | {
decimals: ...;
iconUrl: ...;
id: ...;
name: ...;
symbol: ...;
type: ...;
};
id: string;
metadata: any;
tokenId: string;
};
to: null | {
id: string;
};
token: null | {
decimals: null | number;
iconUrl: null | string;
id: string;
name: null | string;
symbol: null | string;
type: string;
};
transaction: null | {
blockHash: string;
blockNumber: string;
date: string;
fees: string;
gasPrice: string;
gasUsed: string;
id: string;
success: boolean;
};
type: string;
value: string;
};
}[];
pageInfo: {
endCursor: null | string;
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: null | string;
};
totalCount: number;
}>
Retrieves the account transaction history for native currency, tokens, and NFTs.
Returns
Promise
<null
| {
edges
: {
cursor
: null
| string
;
node
: null
| {
decimals
: null
| number
;
from
: null
| {
id
: string
;
};
id
: string
;
nft
: null
| {
collection
: null
| {
decimals
: ...;
iconUrl
: ...;
id
: ...;
name
: ...;
symbol
: ...;
type
: ...;
};
id
: string
;
metadata
: any
;
tokenId
: string
;
};
to
: null
| {
id
: string
;
};
token
: null
| {
decimals
: null
| number
;
iconUrl
: null
| string
;
id
: string
;
name
: null
| string
;
symbol
: null
| string
;
type
: string
;
};
transaction
: null
| {
blockHash
: string
;
blockNumber
: string
;
date
: string
;
fees
: string
;
gasPrice
: string
;
gasUsed
: string
;
id
: string
;
success
: boolean
;
};
type
: string
;
value
: string
;
};
}[];
pageInfo
: {
endCursor
: null
| string
;
hasNextPage
: boolean
;
hasPreviousPage
: boolean
;
startCursor
: null
| string
;
};
totalCount
: number
;
}>
A promise that resolves to the account's transaction history.
Implementation of
KeybanAccount.getTransferHistory
signMessage()
signMessage(message: string): Promise<`0x${string}`>
Signs an Ethereum message.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | The message to be signed. |
Returns
Promise
<`0x${string}`>
- The signed message as a hex string.
Throws
If the message is empty or there is an issue during signing.
Implementation of
KeybanAccount.signMessage
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);
}
};
Implementation of
KeybanAccount.transfer
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);
}
};
Implementation of
KeybanAccount.transferERC20
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);
}
};
Implementation of
KeybanAccount.transferNft