# Ethereum Provider

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

## 지원 네트워크

<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 Testnet</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-testnet</td></tr><tr><td>1001</td><td>Klaytn Testnet</td><td>klaytn</td></tr><tr><td>2731</td><td>TimeNetwork Testnet</td><td>evmtimenetwork-testnet</td></tr></tbody></table>

## 설치(Install)

먼저 `@wepin/widget-sdk`와 `@wepin/provider`를 project에 import 합니다.

```jsx
// 반드시 widget-sdk를 먼저 import 해야합니다. 
import '@wepin/widget-sdk'
import '@wepin/provider'
```

## 초기화(Initialize) Web3.js

먼저 Wepin을 initialize 한 이후에 provider를 얻어와서 web3.js를 초기화 합니다.

```jsx
// web3.js 를 먼저 import 합니다. 
import Web3 from 'web3';

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' });

// wepin provider를 이용해 web3 를 initialize 합니다. 
const web3 = new Web3(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/web-javascript-sdk/provider/ethereum-provider.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.
