본문으로 건너뛰기

EIP-7702

BOT Chain Mainnet과 Testnet은 EIP-7702 Type 4 트랜잭션을 지원합니다. 기존 EOA는 원래 주소, 잔액, 개인키 제어권을 유지하면서 실행 코드를 배포된 계정 구현에 위임하는 권한에 서명할 수 있습니다.

제출 경로는 두 가지입니다.

  • 네이티브 트랜잭션: authorizationList가 포함된 Type 4 트랜잭션을 체인 RPC로 전송합니다.
  • UserOperation: BOT Chain Bundler는 현재 EIP-7702 UserOperation을 지원하지 않습니다. 자체 Bundler에서 구현할 수 있습니다.

네이티브 Type 4 트랜잭션​

네이티브 경로는 EntryPoint와 Bundler를 사용하지 않으며 EOA가 Gas를 지불합니다.

1. 의존성 설치​

npm install viem

2. 클라이언트 생성​

다음 예시는 BOT Chain Testnet을 사용합니다.

import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const botTestnet = {
id: 968,
name: "BOT Chain Testnet",
nativeCurrency: { name: "BOT", symbol: "BOT", decimals: 18 },
rpcUrls: { default: { http: ["https://rpc.bohr.life"] } },
} as const;
const eoa = privateKeyToAccount("0x...");
const publicClient = createPublicClient({
chain: botTestnet, transport: http("https://rpc.bohr.life"),
});
const walletClient = createWalletClient({
account: eoa, chain: botTestnet, transport: http("https://rpc.bohr.life"),
});

프로덕션 프런트엔드 소스에 개인키를 저장하지 마세요. 지갑 커넥터나 보호된 서명 서비스를 사용합니다.

3. 권한 서명 및 위임 설정​

EOA가 권한 서명자이자 Type 4 트랜잭션 발신자라면 executor: "self"를 설정해 viem이 트랜잭션 nonce와 권한 nonce의 관계를 올바르게 처리하도록 합니다.

const implementation = "0x..." as const;
const authorization = await walletClient.signAuthorization({
account: eoa, contractAddress: implementation, executor: "self",
});
const hash = await walletClient.sendTransaction({
account: eoa, authorizationList: [authorization], to: eoa.address, data: "0x",
});
await publicClient.waitForTransactionReceipt({ hash });

sendTransaction은 EIP-7702 Type 4 트랜잭션을 구성하고 제출합니다. 초기화가 필요하면 같은 트랜잭션에 calldata를 포함합니다.

import { encodeFunctionData } from "viem";
const initializeData = encodeFunctionData({
abi: accountAbi, functionName: "initialize", args: [/* 초기화 인자 */],
});
const hash = await walletClient.sendTransaction({
account: eoa, authorizationList: [authorization],
to: eoa.address, data: initializeData,
});

4. 위임 결과 검증​

const code = await publicClient.getCode({ address: eoa.address });
const expectedCode = `0xef0100${implementation.slice(2).toLowerCase()}`;
if (code?.toLowerCase() !== expectedCode) {
throw new Error("EIP-7702 delegation was not applied");
}

5. 위임 계정 호출​

위임 후에도 호출 대상은 EOA 주소입니다. 계정 구현 ABI에 맞춰 calldata를 인코딩합니다.

import { encodeFunctionData } from "viem";
const callData = encodeFunctionData({
abi: accountAbi, functionName: "execute",
args: [target, value, targetCallData],
});
const hash = await walletClient.sendTransaction({
account: eoa, to: eoa.address, data: callData,
});

비즈니스 대상은 target이며 계정 구현은 앞서 승인한 implementation 주소입니다.