# EVM 호환

Ethers.js 또는 Web3.js를 Wepin Provider와 함께 사용하면 EVM 계열의 블록체인과 상호작용 할 수 있습니다.&#x20;

## 지원 네트워크

{% hint style="info" %}
목록에 필요한 블록체인이 없나요? [위핀 팀에 요청](https://wepinwallet.typeform.com/WEPIN-Wallet)하여 별도의 비용 없이 블록체인을 추가할 수 있습니다.
{% endhint %}

### 메인넷

<table><thead><tr><th width="172.33333333333331">Chain ID</th><th>Network Name</th><th>Network Variable</th></tr></thead><tbody><tr><td>1</td><td>Ethereum Mainnet</td><td>ethereum</td></tr><tr><td>5</td><td>Ethereum Goerli Testnet</td><td>evmeth-goerli</td></tr><tr><td>11155111</td><td>Ethereum Sepolia</td><td>evmeth-sepolia</td></tr><tr><td>19</td><td>Songbird Canary Network</td><td>evmsongbird</td></tr><tr><td>137</td><td>Polygon Mainnet</td><td>evmpolygon</td></tr><tr><td>80002</td><td>Polygon Amoy</td><td>evmpolygon-amoy</td></tr><tr><td>8217</td><td>Klaytn Mainnet</td><td>klaytn</td></tr><tr><td>1001</td><td>Klaytn Testnet</td><td>klaytn-testnet</td></tr><tr><td>2731</td><td>Ant-Time Testnet</td><td>evmanttime-testnet</td></tr></tbody></table>

## 초기화(Initialize) web3.js

먼저 Wepin을 initialize 한 이후에 provider를 얻습니다.&#x20;

```jsx
const appId = 'app_id_eg12sf3491azgs520' // 테스트용 앱 ID
const appKey = 'ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313' // 테스트용 앱 키
const attributes = {
	type: 'show'
}
// Wepin을 initialize 합니다. 
await Wepin.init(appId, appKey, attributes)
// initialize 된 Wepin으로 부터 provider를 얻어 옵니다. 
const provider = Wepin.getProvider({ network: 'ethereum' });
```

### \`web3.js\` 를 이용한 web3 초기화

```javascript
import Web3 from 'web3'
const provider = Wepin.getProvider({ network: 'ethereum' })
const web3 = new Web3(provider)
```

### \`ethers.js\`를 이용한 web3 초기화

참고 문서: [ethers.js for React native](https://docs.ethers.org/v5/cookbook/react-native/)

```javascript
import "react-native-get-random-values"
// Import the the ethers shims (**BEFORE** ethers)
import "@ethersproject/shims"
// Import the ethers library
import { ethers } from "ethers"
const provider = wepin.getProvider({ network: 'ethereum' })
const web3 = new ethers.providers.Web3Provider(provider)
```

## 메서드(Method)

### Get Accounts

초기화된 web3를 통해서 account 정보를 받아 올 수 있습니다.

```jsx
const accounts = await web3.eth.getAccounts()
```

### Get Balance

account 정보를 이용해 balance를 조회할 수 있습니다.

```jsx
const balance = await web3.eth.getBalance(accounts[0])
```

아래 링크를 참고하여 Balance 뿐만 아니라 fee 정보, block number 등을 조회할 수 있습니다.

{% embed url="<https://web3js-kr.readthedocs.io/ko/latest/getting-started.html>" %}

### Send Transaction

transaction을 전송할 수 있습니다.

```jsx
const accounts = await web3.eth.getAccounts()
const tx = {
    from: accounts[0],
    gasPrice: "2000000000",
    gas: "21000",
    to: '0x11f4d0A3c1......13F7E19D048276DAe',
    value: "10000000000000000",
}
const response = await web3.eth.sendTransaction(tx)
```

### Contract Call

contract call을 수행할 수 있습니다.

```jsx
const callObject = {
	to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', //contract address
	data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003'
}
const response = await web3.eth.call(callObject)
```

이더리움 호환 네트워크 프로바이더의 자세한 내용은 아래 링크를 참고하세요.

{% embed url="<https://eips.ethereum.org/EIPS/eip-1193>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/deprecated/react-native-sdk/provider/evmcompatible.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
