> For the complete documentation index, see [llms.txt](https://be-technology.gitbook.io/web3library-for-unity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://be-technology.gitbook.io/web3library-for-unity/how-to-use/connection.md).

# Connection

### Web3Connect

Web3Connect is your main class to connect with a provider, the class is on the namespace Web3Unity.

```
// Import it on your code, add this at the header of your class with other import
using Web3Unity;
```

### RPC provider

You can connect directly to a node and interact with it, you just need a rpc url and a private key (if you need to send transaction).\
Otherwise you can use the generic private key if you only need to call smartcontract.\
This provider works with lot of unity platforms.\ <mark style="color:red;">Care to do not publish your private key, a malicious user can decompile the code and extract the private key, use it as test or for server client, don't publish with your code on github too.</mark>&#x20;

```
// All connection to a provider pass by Web3Connect
Web3Connect.Instance.ConnectRPC("https://rpc.builder0x69.io", "0x3141592653589793238462643383279502884197169399375105820974944592");
```

### WalletConnect

You can use WalletConnect to connect with a compatible wallet, this provider works with lot of unity platforms (WebGL/Editor/Windows/iOs/Android).\
This provider can only send/sign transaction through the user's wallet, if you need to call smartcontract add a rpc url.

<pre><code>// It's async class
<strong>await Web3Connect.Instance.ConnectWalletConnect("https://rpc.ankr.com/fantom_testnet");
</strong></code></pre>

You need to get the Uri generate by WalletConnect to connect, on mobile you just need to open the url on other platforms you need to generate a QR code, you have an exemple in Web3Modal.cs

```
// To get the uri generated by walletconnect just subscribe to uri generated event
void Start()
{
    Web3Connect.Instance.UriGenerated += Instance_UriGenerated;
}

// e is the uri
private void Instance_UriGenerated(object sender, string e)
{
 // your code
}
```

### Metamask

You can use the metamask browser wallet only on WebGL platform (for other platform use walletconnect).

```
// Pass true if you want to request connection to user wallet
Web3Connect.Instance.ConnectMetamask(true);
```

&#x20;

### Events

You have different when you connect to a metamask or walletconnect

#### OnConnected (Metamask/WalletConnect)

You can subscribe to connect event, to know when an user connect to your app and receive the account address&#x20;

```
void Start()
{
    Web3Connect.Instance.OnConnected += Instance_Connected;
}
 
// e is the public address of the user 
private void Instance_Connected(object sender, string e)
{

}
```
