How to add Arthera subscriptions to your Solidity contracts
Tags: tutorial, solidity, arthera, dsaas
Published: 2023-10-11 14:12:15

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](https://www.biconomy.io/), [Gelato](https://www.gelato.network/) 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](https://bitpushnews.medium.com/eip-4337-will-account-abstraction-bring-mass-adoption-to-ethereum-2293c1a28137), the Ethereum community collectively [decided](https://eips.ethereum.org/EIPS/eip-4337) to natively support what we now call _smart wallets_ or _on-chain wallets_, referring to account abstraction implementations. [Etherspot](https://etherspot.io/), [Cometh Connect](https://docs.cometh.io/connect/quickstart/what-is-connect) or [Safe](https://safe.global/core), and several others are making it easier for devs to integrate with account abstraction to improve the UX for their own app. At [Arthera](https://docs.arthera.net/build/intro) we will hopefully work with all of them. However, as Fabian Vogelsteller mentioned in a [recent interview](https://twitter.com/lukso_io/status/1685255791777869825), 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z36km0w64bx4l49uy05h.png)

--- 

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](https://smp-dev.arthera.net/)) 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](https://wallet-test.arthera.net/) 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: 

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

interface ISubscriptionOwner {
    function getSubscriptionOwner() external view returns (address);
}
```

_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: 

```js
import "./ISubscriptionOwner.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
```

### Step 4

Make your contract inherit from both `ISubscriptionOwner` and `ERC165`:

```js
contract YourContract is ISubscriptionOwner, ERC165 {
    // ... 
}
```

### Step 5

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

```js
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);
}
```

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:

```js
function getSubscriptionOwner() external view returns (address) {
    return owner();
}
```

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: 

- RPC Endpoint: **https://rpc-test.arthera.net**
- Chain ID: **10243**

### Step 7

- Go to the Arthera [SMP](https://smp-test.arthera.net) (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

- [Tech support TG group](https://t.me/artherachain/8)
- [Arthera documentation](https://docs.arthera.net/build/intro)
- [Integration recommendations](https://docs.arthera.net/build/intro)
- [Website](https://www.arthera.net/)
- [App Store](https://store.arthera.net/)
- [Arthera White Paper NFT](https://whitepaper.arthera.net/)

Thanks for reading!