Balance Approvals
Use balance approvals to share balances between multiple addresses. This helps to onboard users without requiring them to own tokens.
With balance approvals:
- You pay for transactions.
- Users sign transactions.
Balance approvals:
- Are based on the token set when connecting to an Irys node. Both approver and approvee must use the same token.
- Are registered instantly upon upload completion.
- Are non-transferable.
- Can be configured to expire automatically.
Create an Approval
To update an existing approval, create a new approval with the same address (it will overwrite the existing approval).
const receipt = await irys.approval.createApproval({
amount: irys.utils.toAtomic(1), // Amount in atomic units
approvedAddress: "<address>",
expiresInSeconds: 100, // Expires in 100 seconds. Delete to remove expiration.
});
Upload Using an Approval
const receipt = await irys.upload("GM World", { upload: { paidBy: "<address>" } });
Combine approvals and tags:
const uploadOptions = {
upload: {
paidBy: "<address>",
},
tags: [{ name: "Content-Type", value: "text/plain" }],
};
const receipt = await irys.upload(dataToUpload, uploadOptions);
Revoke an Approval
const receipt = await irys.approval.revokeApproval({ approvedAddress: "<address>" });
Get Balances You're Approved To Use
Get approvals from the array of addresses provided:
const approvals = await irys.approval.getApprovals({
payingAddresses: ["<address>"],
});
Get the first 100 approvals:
const approvals = await irys.approval.getApprovals({});
Return type:
{
amount: string; // Amount approved in atomic units
payingAddress: string; // Address of the payer's wallet
approvedAddress: string; // Address of the wallet that received the approval
expiresBy: number; // Timestamp (in milliseconds) when approval expires
timestamp: number; // Timestamp (in milliseconds) when the approval was created
token: string; // Approved token
}
[];
Get Approvals You've Created
Get approvals for the array of addresses provided:
const createdApprovals = irys.approval.getCreatedApprovals({
approvedAddresses: ["<address>"],
});
Get the first 100 approvals you've created:
const createdApprovals = irys.approval.getCreatedApprovals({});
Return type:
{
amount: string; // Amount approved in atomic units
payingAddress: string; // Address of the payer's wallet
approvedAddress: string; // Address of the wallet that received the approval
expiresBy: number; // Timestamp (in milliseconds) when approval expires
timestamp: number; // Timestamp (in milliseconds) when the approval was created
token: string; // Approved token
}
[];
Get Balance Approvals via HTTP
You can also request balance approvals via HTTP:
Testnet:
https://testnet.irys.xyz/account/approval?payingAddress=<...>&token=<...>&approvedAddress=<...>