@ethersproject/bytes#hexConcat TypeScript Examples
The following examples show how to use
@ethersproject/bytes#hexConcat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: serializeTransaction.ts From bodhi.js with Apache License 2.0 | 6 votes |
// rlp([chainId, salt, nonce, gasLimit, storageLimit, to, value, data, validUntil, tip, accessList, eip712sig])
export function serializeEip712(transaction: UnsignedAcalaEvmTX, signature?: SignatureLike): string {
const fields: any = [
formatNumber(transaction.chainId || 0, 'chainId'),
transaction.salt || '0x',
formatNumber(transaction.nonce || 0, 'nonce'),
formatNumber(transaction.gasLimit || 0, 'gasLimit'),
formatNumber(transaction.storageLimit || 0, 'storageLimit'),
transaction.to === null || transaction.to === undefined ? '0x' : getAddress(transaction.to),
formatNumber(transaction.value || 0, 'value'),
transaction.data || '0x',
formatNumber(transaction.validUntil || MAX_UINT256, 'validUntil'),
formatNumber(transaction.tip || 0, 'tip'),
formatAccessList(transaction.accessList || [])
];
if (signature) {
const sig = splitSignature(signature);
fields.push(formatNumber(sig.recoveryParam, 'recoveryParam'));
fields.push(stripZeros(sig.r));
fields.push(stripZeros(sig.s));
}
return hexConcat(['0x60', RLP.encode(fields)]);
}
Example #2
Source File: call.ts From ethcall with MIT License | 6 votes |
async function callDeployless(
provider: BaseProvider,
callRequests: CallRequest[],
block?: BlockTag,
): Promise<Result> {
const inputAbi: JsonFragment[] = deploylessMulticallAbi;
const constructor = inputAbi.find((f) => f.type === 'constructor');
const inputs = constructor?.inputs || [];
const args = Abi.encodeConstructor(inputs, [callRequests]);
const data = hexConcat([deploylessMulticallBytecode, args]);
const callData = await provider.call(
{
data,
},
block,
);
const outputAbi: JsonFragment[] = multicallAbi;
const outputFunc = outputAbi.find(
(f) => f.type === 'function' && f.name === 'aggregate',
);
const name = outputFunc?.name || '';
const outputs = outputFunc?.outputs || [];
const response = Abi.decode(name, outputs, callData);
return response;
}
Example #3
Source File: call.ts From ethcall with MIT License | 6 votes |
async function callDeployless2(
provider: BaseProvider,
callRequests: CallRequest[],
block?: BlockTag,
): Promise<Result> {
const inputAbi: JsonFragment[] = deploylessMulticall2Abi;
const constructor = inputAbi.find((f) => f.type === 'constructor');
const inputs = constructor?.inputs || [];
const args = Abi.encodeConstructor(inputs, [false, callRequests]);
const data = hexConcat([deploylessMulticall2Bytecode, args]);
const callData = await provider.call(
{
data,
},
block,
);
const outputAbi: JsonFragment[] = multicall2Abi;
const outputFunc = outputAbi.find(
(f) => f.type === 'function' && f.name === 'tryAggregate',
);
const name = outputFunc?.name || '';
const outputs = outputFunc?.outputs || [];
// Note "[0]": low-level calls don't automatically unwrap tuple output
const response = Abi.decode(name, outputs, callData)[0];
return response as CallResult[];
}
Example #4
Source File: call.ts From ethcall with MIT License | 6 votes |
async function callDeployless3(
provider: BaseProvider,
callRequests: CallRequest[],
block?: BlockTag,
): Promise<Result> {
const inputAbi: JsonFragment[] = deploylessMulticall3Abi;
const constructor = inputAbi.find((f) => f.type === 'constructor');
const inputs = constructor?.inputs || [];
const args = Abi.encodeConstructor(inputs, [callRequests]);
const data = hexConcat([deploylessMulticall3Bytecode, args]);
const callData = await provider.call(
{
data,
},
block,
);
const outputAbi: JsonFragment[] = multicall3Abi;
const outputFunc = outputAbi.find(
(f) => f.type === 'function' && f.name === 'aggregate3',
);
const name = outputFunc?.name || '';
const outputs = outputFunc?.outputs || [];
// Note "[0]": low-level calls don't automatically unwrap tuple output
const response = Abi.decode(name, outputs, callData)[0];
return response as CallResult[];
}
Example #5
Source File: index.ts From ccip-read with MIT License | 5 votes |
async function handleCall(
provider: CCIPReadProvider,
params: { transaction: TransactionRequest; blockTag?: BlockTag },
maxCalls = 4
): Promise<{ transaction: TransactionRequest; result: BytesLike }> {
for (let i = 0; i < maxCalls; i++) {
let result;
let bytes: Uint8Array;
try {
result = await provider.parent.perform('call', params);
bytes = arrayify(result);
} catch (e) {
if (isRevertError(e)) {
bytes = arrayify(e.error.data.originalError.data);
} else {
return logger.throwError('The error message does not contain originalError', Logger.errors.UNKNOWN_ERROR);
}
}
if (bytes.length % 32 !== 4 || hexlify(bytes.slice(0, 4)) !== CCIP_READ_INTERFACE.getSighash('OffchainLookup')) {
return { transaction: params.transaction, result: bytes };
}
const { sender, urls, callData, callbackFunction, extraData } = CCIP_READ_INTERFACE.decodeErrorResult(
'OffchainLookup',
bytes
);
if (params.transaction.to === undefined || sender.toLowerCase() !== params.transaction.to.toLowerCase()) {
return logger.throwError('OffchainLookup thrown in nested scope', Logger.errors.UNSUPPORTED_OPERATION, {
to: params.transaction.to,
sender,
urls,
callData,
callbackFunction,
extraData,
});
}
const response = await sendRPC(provider.fetcher, urls, params.transaction.to, callData);
const data = hexConcat([
callbackFunction,
defaultAbiCoder.encode(CCIP_READ_INTERFACE.getFunction('callback').inputs, [response, extraData]),
]);
params = Object.assign({}, params, {
transaction: Object.assign({}, params.transaction, { data }),
});
}
return logger.throwError('Too many redirects', Logger.errors.TIMEOUT, { to: params.transaction.to });
}