Skip to content

Commit

Permalink
Update deploy-contract.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy committed Dec 11, 2024
1 parent bef5c89 commit 4c561e5
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions stellar/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,40 +97,40 @@ async function deploy(options, config, chain, contractName) {
return;
}

const initializeArgs = await getInitializeArgs(config, chain, contractName, wallet, options);
const serializedArgs = Object.fromEntries(
Object.entries(initializeArgs).map(([key, value]) => [key, serializeValue(scValToNative(value))]),
);
const wasmHash = await uploadWasm(wasmPath, wallet, chain);

if (contractName === 'interchain_token') {
chain.contracts[contractName] = {
deployer: wallet.publicKey(),
wasmHash: serializeValue(wasmHash),
};
printInfo(contractName, JSON.stringify(chain.contracts[contractName], null, 2));
return;
}
} else {
const initializeArgs = await getInitializeArgs(config, chain, contractName, wallet, options);
const serializedArgs = Object.fromEntries(
Object.entries(initializeArgs).map(([key, value]) => [key, serializeValue(scValToNative(value))]),
);
const operation = Operation.createCustomContract({
wasmHash,
address: Address.fromString(wallet.publicKey()),
// requires that initializeArgs returns the parameters in the appropriate order
constructorArgs: Object.values(initializeArgs),
});
printInfo('Initializing contract with args', JSON.stringify(serializedArgs, null, 2));

const operation = Operation.createCustomContract({
wasmHash,
address: Address.fromString(wallet.publicKey()),
// requires that initializeArgs returns the parameters in the appropriate order
constructorArgs: Object.values(initializeArgs),
});
printInfo('Initializing contract with args', JSON.stringify(serializedArgs, null, 2));
const deployResponse = await broadcast(operation, wallet, chain, 'Initialized contract', options);
const contractAddress = StrKey.encodeContract(Address.fromScAddress(deployResponse.address()).toBuffer());

const deployResponse = await broadcast(operation, wallet, chain, 'Initialized contract', options);
const contractAddress = StrKey.encodeContract(Address.fromScAddress(deployResponse.address()).toBuffer());
printInfo('Contract initialized at address', contractAddress);

printInfo('Contract initialized at address', contractAddress);
chain.contracts[contractName] = {
address: contractAddress,
deployer: wallet.publicKey(),
wasmHash: serializeValue(wasmHash),
initializeArgs: serializedArgs,
};
}

chain.contracts[contractName] = {
address: contractAddress,
deployer: wallet.publicKey(),
wasmHash: serializeValue(wasmHash),
initializeArgs: serializedArgs,
};
printInfo(contractName, JSON.stringify(chain.contracts[contractName], null, 2));
}

async function uploadWasm(filePath, wallet, chain) {
Expand Down

0 comments on commit 4c561e5

Please sign in to comment.