# Ethereum Coin98 Telegram Wallet SDK Bot Integration For Vanilla Javascript

Welcome to Coin98 Telegram Wallet Developer Guide.

This documentation guides developers building on the Coin98 Telegram Wallet using **Javascript.** Any methods not listed here aren’t supported at the moment.

**Outline**

* [Initialize SDK](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-initializesdk)
* [Experience functions](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-experiencefunctions)
  * [1. Transfer](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-1.transfer)
  * [2. Decrypt](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-2.decrypt)
  * [3. Get Encryption Public Key](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-3.getencryptionpublickey)
  * [4. Encrypt](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-4.encrypt)
  * [5. Switch Ethereum Chain](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-5.switchethereumchain)
  * [6. Sign Typed Data](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-6.signtypeddata)
  * [7. Sign Typed Data V3](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-7.signtypeddatav3)
  * [8. Sign Typed Data V4](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-8.signtypeddatav4)
  * [9. Personal Sign](#ethereumsuperwalletsdkbotintegrationforvanillajavascript-9.personalsign)

## Initialize SDK <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-initializesdk" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-initializesdk"></a>

```
import { Coin98SDK } from  "@coin98-com/telegram-connect-sdk";

export  const  CHAIN_ID  =  '0x38'
const PARTNER = 'eternals'
export  const  coin98SDK  =  new  Coin98SDK(PARTNER, CHAIN_ID)
```

**Chain Supported**

```
import {SupportChain} from "@coin98-com/telegram-connect-sdk"
```

**Explain:**

* CHAIN\_ID: specific chain id evm
* PARTNER: specific partner to know which is connecting

**Connect Coin98 Telegram Wallet**

To connect Coin98 Telegram Wallet means to access the user's \[blockchain - like Ethereum] account(s).

```
const addressConnected = await coin98SDK.connect(SupportChain.evm)
setAddress(addressConnected)
```

## Experience functions <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-experiencefunctions" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-experiencefunctions"></a>

Once your account is connected, let's start experiencing more functions.‌

#### 1. Transfer <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-1.transfer" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-1.transfer"></a>

return `Promise<hash>` - Initiates a new transaction.

```
const result = await coin98SDK.handle({
	chain: SupportChain.evm,
	method: 'eth_sendTransaction',
	data: {
		from: address,
		to: address,
		value: '0x0'
	}
})
```

#### 2. Decrypt <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-2.decrypt" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-2.decrypt"></a>

return `Promise<string>` - Decrypts an encrypted message.

```
const res = await coin98SDK.handle({
	method: 'eth_decrypt',
	chain: SupportChain.evm,
	data: {
		message: <DATA_ENCRYPT>
	}
})
```

#### 3. Get Encryption Public Key <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-3.getencryptionpublickey" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-3.getencryptionpublickey"></a>

return `Promise<string>`- The public encryption key of the Ethereum account whose encryption key should be retrieved

```
const result = await coin98SDK.handle({
	method: 'eth_getEncryptionPublicKey',
	chain: SupportChain.evm
})
```

#### 4. Encrypt <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-4.encrypt" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-4.encrypt"></a>

return `Promise<string>` - Encrypted message.

```
const result = await coin98SDK.handle({
	method: 'encryptKey',
	data: value,
	chain: SupportChain.evm
})
```

#### 5. Switch Ethereum Chain <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-5.switchethereumchain" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-5.switchethereumchain"></a>

* In our current flow, simply change the `chainId` in parameters before using any method.
* Our Coin98 Telegram Wallet Bot will automatically detect and switch chains accordingly

#### 6. Sign Typed Data <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-6.signtypeddata" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-6.signtypeddata"></a>

return `Promise<string>` - Presents a structured data message for the user to sign.

```
const result = await coin98SDK.handle({
	method: 'eth_signTypedData',
	chain: SupportChain.evm,
	data: [
		{
			"type": "string",
			"name": "Message",
			"value": "Hi, Alice!"
		},
		{
			"type": "uint32",
			"name": "A number",
			"value": "1337"
		}
	]
})
```

#### 7. Sign Typed Data V3 <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-7.signtypeddatav3" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-7.signtypeddatav3"></a>

return `Promise<string>` - Presents a structured data message for the user to sign.

```
const result = await coin98SDK.handle({
	chain: SupportChain.evm,
	method: 'eth_signTypedDataV3',
	data: {
		types: {
			EIP712Domain: [
				{ name: "name", type: "string" },
				{ name: "version", type: "string" },
				{ name: "chainId", type: "uint256" },
				{ name: "verifyingContract", type: "address" },
			],
			Person: [
				{ name: 'name', type: 'string' },
				{ name: 'wallet', type: 'address' },
			],
			Mail: [
				{ name: 'from', type: 'Person' },
				{ name: 'to', type: 'Person' },
				{ name: 'contents', type: 'string' },
			],
		},
		primaryType: 'Mail',
		domain: {
			name: 'Ether Mail',
			version: '1',
			chainId: Number(coin98SDK.chainId),
			verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
		},
		message: {
			from: {
				name: 'Cow',
				wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
			},
			to: {
				name: 'Bob',
				wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
			},
			contents: 'Hello, Bob!',
		},
	}
})
```

#### 8. Sign Typed Data V4 <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-8.signtypeddatav4" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-8.signtypeddatav4"></a>

return `Promise<string>` - Presents a structured data message for the user to sign.

```
await coin98SDK.handle({
	method: 'eth_signTypedDataV4',
	chain: SupportChain.evm,
	data: {
		domain: {
			chainId: Number(coin98SDK.chainId),
			name: 'Ether Mail',
			verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
			version: '1',
		},
		message: {
			contents: 'Hello, Bob!',
			from: {
				name: 'Cow',
				wallets: [
					'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
					'0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
				],
			},
			to: [
					{
						name: 'Bob',
						wallets: [
							'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
							'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
							'0xB0B0b0b0b0b0B000000000000000000000000000',
						],
					},
				],
				attachment: '0x',
			},
			primaryType: 'Mail',
			types: {
				EIP712Domain: [
					{ name: "name", type: "string" },
					{ name: "version", type: "string" },
					{ name: "chainId", type: "uint256" },
					{ name: "verifyingContract", type: "address" },
				],
				Group: [
					{ name: 'name', type: 'string' },
					{ name: 'members', type: 'Person[]' },
				],
				Mail: [
					{ name: 'from', type: 'Person' },
					{ name: 'to', type: 'Person[]' },
					{ name: 'contents', type: 'string' },
					{ name: 'attachment', type: 'bytes' },
				],
				Person: [
					{ name: 'name', type: 'string' },
					{ name: 'wallets', type: 'address[]' },
				],
			}
		}
	})
```

#### 9. Personal Sign <a href="#ethereumsuperwalletsdkbotintegrationforvanillajavascript-9.personalsign" id="ethereumsuperwalletsdkbotintegrationforvanillajavascript-9.personalsign"></a>

return `Promise<string>` - Presents a plain text signature challenge to the user.

```
const result = await coin98SDK.handle({
	chain: SupportChain.evm,
	method: 'personal_sign',
	data: {
		message: 'This is message'
	}
})
```
