Class.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 | Modifier | Type | Description |
---|---|---|---|
address | abstract | string | The blockchain address associated with the account. |
publicKey | abstract | string | The public key associated with the account. |
Methods
estimateERC20Transfer()
abstract 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()
abstract 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()
abstract estimateTransfer(to: string): Promise<FeesEstimation>;
Estimates the cost of transferring native tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
to | 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.
loyaltyDestroy()
loyaltyDestroy(): Promise<void>;
Internal
Destroys the loyalty setup for the account.
Returns
Promise
<void
>
A promise that resolves when the loyalty setup is destroyed.
loyaltySetup()
loyaltySetup(): Promise<void>;
Sets up the account for the loyalty application. This method signs a setup transaction and submits it to the network. It makes the account ready to be used with the loyalty application. It depends on the blockchain network.
Returns
Promise
<void
>
A promise that resolves when the setup is complete.
signMessage()
abstract signMessage(message: string): Promise<string | string[]>;
Signs an Ethereum message.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | The message to be signed. |
Returns
Promise
<string
| string
[]>
- The signed message as a hex string.
Throws
If the message is empty or there is an issue during signing.
signTransaction()
abstract signTransaction(txHash: string): Promise<string | string[]>;
Internal
Signs a transaction hash.
Parameters
Parameter | Type | Description |
---|---|---|
txHash | string | The transaction hash to be signed in hex string format. |
Returns
Promise
<string
| string
[]>
- The signed transaction as a hex string or an array of hex strings.
Throws
If the transaction hash is invalid or there is an issue during signing.
tppClaim()
tppClaim(tppId: string): Promise<{
transactionHash: string;
}>;
Claims a TPP for a given recipient.
Parameters
Parameter | Type | Description |
---|---|---|
tppId | string | The identifier of the Tokenized Product Passport (TPP) to claim. |
Returns
Promise
<{
transactionHash
: string
;
}>
A promise that resolves with the result of the RPC call.
transfer()
abstract transfer(
to: string,
value: bigint,
fees?: FeeDetails): Promise<string>;
Transfers native tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
to | string | The recipient's address. |
value | bigint | The transfer amount in wei (must be greater than 0). |
fees? | FeeDetails | Optional transaction fees. |
Returns
Promise
<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()
abstract transferERC20(params: TransferERC20Params): Promise<string>;
Transfers ERC20 tokens to another address.
Parameters
Parameter | Type | Description |
---|---|---|
params | TransferERC20Params | The parameters for the ERC20 transfer. |
Returns
Promise
<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()
abstract 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);
}
};