encodeDeployData
Encodes deploy data (bytecode & constructor args) into an ABI encoded value.
Install
import { encodeDeployData } from "cive";Usage
Below is a very basic example of how to encode deploy data.
import { } from "cive";
import { } from "./abi.js";
const = ({
: ,
: "0x...",
});
// 0x...export const Abi = [
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor",
},
] as const;Passing Arguments
If your constructor requires argument(s), you can pass them through with the args attribute.
TypeScript types for args will be inferred from the constructor & ABI, to guard you from inserting the wrong values.
For example, the constructor below requires an address argument, and it is typed as ["0x${string}"].
import { encodeDeployData } from "cive";
import { Abi } from "./abi";
const data = encodeDeployData({
abi: Abi,
bytecode: "0x608060405260405161083e38038061083e833981016040819052610...",
args: ["cfx:..."],
});
// 0x...export const Abi = [
{
inputs: [{ name: "owner", type: "address" }],
stateMutability: "nonpayable",
type: "constructor",
},
] as const;Return Value
ABI encoded data (bytecode & constructor arguments).
Parameters
abi
- Type:
Abi
The contract's ABI.
const data = encodeDeployData({
abi: Abi,
bytecode: "0x608060405260405161083e38038061083e833981016040819052610...",
args: ["cfx:..."],
});bytecode
- Type:
Hex
Contract bytecode.
const data = encodeDeployData({
abi: Abi,
bytecode: "0x608060405260405161083e38038061083e833981016040819052610...",
args: ["cfx:..."],
});args (optional)
- Type: Inferred from ABI.
Arguments to pass to function call.
const data = encodeDeployData({
abi: Abi,
bytecode: "0x608060405260405161083e38038061083e833981016040819052610...",
args: ["cfx:..."],
});