DEV Community

Cover image for How to add Arthera subscriptions to your Solidity contracts
Julien Béranger
Julien Béranger

Posted on • Edited on

How to add Arthera subscriptions to your Solidity contracts

Forcing users to buy a handful of ETH before they can interact with your contract often makes it unpleasant for them to use your service. It's a classic issue in the crypto space and we all know this kind of friction can make your beloved users leave, never to return again.

Teams like Biconomy, Gelato and others have been working hard to create solutions that remove this friction, mainly by allowing your app to sponsor the transaction fees.

On March 1st, 2023, the Ethereum community collectively decided to natively support what we now call smart wallets or on-chain wallets, referring to account abstraction implementations. Etherspot, Cometh Connect or Safe, and several others are making it easier for devs to integrate with account abstraction to improve the UX for their own app. At Arthera we will hopefully work with all of them. However, as Fabian Vogelsteller mentioned in a recent interview, account abstraction can be pretty complex.

Arthera's approach to fix the classical Web3 UX issue is pretty straight forward. If you want to pay for your gas fees you can: we call it "pay-as-you-go" and it can be useful in some cases. But one of the key features of Arthera is the built-in subscription model where, as an individual, you can purchase a $1 USD monthly subscription and then just forget about gas fees. Moreover, As an app provider, you can present a gas-less service to your users and that's the part I will cover in this tutorial.

Enough talking for today... let’s build!

Image description


When you get a subscription plan for your app, you can then whitelist your users so they can use your service even if they have zero AA (the native currency of Arthera) in their wallet.

In addition to that, the SMP (Subscription Management Platform) will allow you to customise certain things, and also create a subscription widget that supports fiat payments. This widget can be easily integrated into your app. To my knowledge this is a world first.

Step 1

Go to Arthera Wallet UI v1 and export the private key to your smart contract development environment (Hardhat, Foundry, etc).

Step 2

Add the ISubscriptionOwner.sol contract interface to your project:

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

interface ISubscriptionOwner {
    function getSubscriptionOwner() external view returns (address);
}
Enter fullscreen mode Exit fullscreen mode

Note: you can also directly add this contract in your contract file.

Step 3

Add the following imports at the top of your Solidity contract file:

import "./ISubscriptionOwner.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
Enter fullscreen mode Exit fullscreen mode

Step 4

Make your contract inherit from both ISubscriptionOwner and ERC165:

contract YourContract is ISubscriptionOwner, ERC165 {
    // ... 
}
Enter fullscreen mode Exit fullscreen mode

Step 5

Add the getSubscriptionOwner() and supportsInterface() functions at the end of your contract:

function getSubscriptionOwner() external view returns (address) {
    return <ADDRESS_OF_THE_SUBSCRIPTION_OWNER>;
}

function supportsInterface(bytes4 interfaceId) public view override(ERC165) returns (bool) {
    return interfaceId == type(ISubscriptionOwner).interfaceId || super.supportsInterface(interfaceId);
}
Enter fullscreen mode Exit fullscreen mode

The address <ADDRESS_OF_THE_SUBSCRIPTION_OWNER> must be the account you created in the beginning of this tutorial (step 1).

The ISubscriptionOwner interface allows Arthera to determine the owner of the subscription, which must be an EOA account (it can't be a contract).

If your contract is ownable, your getSubscriptionOwner() function would eventually look like this:

function getSubscriptionOwner() external view returns (address) {
    return owner();
}
Enter fullscreen mode Exit fullscreen mode

If your contracts inherit from other contracts, you must ensure the order of inheritances is correct; keep in mind that the ERC165 often goes first.

Step 6

Deploy your contract to Arthera Testnet.

Here is the network info:

Step 7

  • Go to the Arthera SMP (Subscription Management Platform)
  • In the left menu, click on the "On-Chain" tab
  • Connect with the subscription owner wallet
  • Click on "Subscribe" (DApp Plan)
  • Paste your contract address in the field

You should always use the same account, it's what we call the subscriptionOwner. Get a dApp subscription, then paste the address of your newly deployed contract in the field.

Done! 🎉

At this stage, you're ready to whitelist your users so they can interact with your app without paying any gas fees.

Welcome to Arthera: Enjoy Web3, forget gas fees.


Useful links

Thanks for reading!

Top comments (0)