Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// A regular transfer operation is made. No smart contract calls required for this scenario.
const opTransferToContract = await Tezos.contract.transfer({ to: contract.address, amount: 1 })
await opTransferToContract.confirmation();
expect(op.status).toEqual('applied')
// Transfer from contract (kt1_alice) to implicit account (tz1)
// We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
// the specified number (50) of mutez to the target address.
const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50)).send({ amount: 0 })
await opTransfer.confirmation();
expect(opTransfer.status).toEqual('applied')
// Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
await opSetDelegate.confirmation();
expect(opSetDelegate.status).toEqual('applied')
// Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
await removeDelegateOp.confirmation();
expect(removeDelegateOp.status).toEqual('applied')
// Transfer from contract (kt1_alice) to contract (kt1 bob)
// Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
// lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
// in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
// contract.
const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
await transferToContractOp.confirmation();
expect(transferToContractOp.status).toEqual('applied')
done();
})
})
})
const contract = await op.contract();
expect(op.status).toEqual('applied')
// Transfer from implicit account (tz1) to contract (kt1_alice)
// A regular transfer operation is made. No smart contract calls required for this scenario.
const opTransferToContract = await Tezos.contract.transfer({ to: contract.address, amount: 1 })
await opTransferToContract.confirmation();
expect(op.status).toEqual('applied')
// Transfer from contract (kt1_alice) to implicit account (tz1)
// We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
// the specified number (50) of mutez to the target address.
const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50)).send({ amount: 0 })
await opTransfer.confirmation();
expect(opTransfer.status).toEqual('applied')
// Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
await opSetDelegate.confirmation();
expect(opSetDelegate.status).toEqual('applied')
// Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
await removeDelegateOp.confirmation();
expect(removeDelegateOp.status).toEqual('applied')
// Transfer from contract (kt1_alice) to contract (kt1 bob)
// Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
// lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
// in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
// contract.
const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
await transferToContractOp.confirmation();
expect(transferToContractOp.status).toEqual('applied')
done();
})
const op = await Tezos.contract.originate({
balance: "1",
code: managerCode,
init: { "string": await Tezos.signer.publicKeyHash() },
})
const contract = await op.contract();
expect(op.status).toEqual('applied')
// Transfer from implicit account (tz1) to contract (kt1_alice)
// A regular transfer operation is made. No smart contract calls required for this scenario.
const opTransferToContract = await Tezos.contract.transfer({ to: contract.address, amount: 1 })
await opTransferToContract.confirmation();
expect(op.status).toEqual('applied')
// Transfer from contract (kt1_alice) to implicit account (tz1)
// We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
// the specified number (50) of mutez to the target address.
const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50)).send({ amount: 0 })
await opTransfer.confirmation();
expect(opTransfer.status).toEqual('applied')
// Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
await opSetDelegate.confirmation();
expect(opSetDelegate.status).toEqual('applied')
// Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
await removeDelegateOp.confirmation();
expect(removeDelegateOp.status).toEqual('applied')
// Transfer from contract (kt1_alice) to contract (kt1 bob)
// Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
// lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
// in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
// contract.
const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
await opTransfer.confirmation();
expect(opTransfer.status).toEqual('applied')
// Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
await opSetDelegate.confirmation();
expect(opSetDelegate.status).toEqual('applied')
// Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
await removeDelegateOp.confirmation();
expect(removeDelegateOp.status).toEqual('applied')
// Transfer from contract (kt1_alice) to contract (kt1 bob)
// Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
// lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
// in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
// contract.
const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
await transferToContractOp.confirmation();
expect(transferToContractOp.status).toEqual('applied')
done();
})
})
export const CONFIGS = providers.map((provider) => {
const Tezos = new TezosToolkit();
Tezos.setProvider({ rpc: provider })
return {
rpc: provider, lib: Tezos, setup: async () => {
let faucetKey = {
email: "peqjckge.qkrrajzs@tezos.example.org",
password: "y4BX7qS1UE", mnemonic: [
"skate",
"damp",
"faculty",
"morning",
"bring",
"ridge",
"traffic",
"initial",
"piece",
"annual",
it('Simple set delegate', async (done) => {
const delegate = 'tz1PirboZKFVqkfE45hVLpkpXaZtLk3mqC17'
const op = await Tezos.contract.setDelegate({
delegate,
source: await Tezos.signer.publicKeyHash(),
fee: DEFAULT_FEE.DELEGATION,
gasLimit: DEFAULT_GAS_LIMIT.DELEGATION
})
await op.confirmation()
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY)
const account = await Tezos.rpc.getDelegate(await Tezos.signer.publicKeyHash())
expect(account).toEqual(delegate)
done();
});
it('Simple set delegate', async (done) => {
const delegate = 'tz1PirboZKFVqkfE45hVLpkpXaZtLk3mqC17'
const op = await Tezos.contract.setDelegate({
delegate,
source: await Tezos.signer.publicKeyHash(),
fee: DEFAULT_FEE.DELEGATION,
gasLimit: DEFAULT_GAS_LIMIT.DELEGATION
})
await op.confirmation()
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY)
const account = await Tezos.rpc.getDelegate(await Tezos.signer.publicKeyHash())
expect(account).toEqual(delegate)
done();
});
async function example() {
const provider = 'https://alphanet-node.tzscan.io';
const signer: any = new InMemorySigner('edsk3xkqabYfWWpcEKTWk75cRQv2bgHA3EHuuHSFH3ejqzKPx69Zh9');
Tezos.setProvider({ rpc: provider, signer });
try {
const contract = await Tezos.contract.at('KT1SawqvsVdAbDzqc4KwPpaS1S1veuFgF9AN');
console.log("Printing contract methods...");
console.log(contract.methods);
console.log("Showing initial storage...");
console.log(await contract.storage())
const op = await contract.methods.mint("tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn", 100).send({ fee: 30000, gasLimit: 200000 })
console.log('Awaiting confirmation...');
await op.confirmation();
console.log(op.hash, op.includedInBlock);
console.log("Showing final storage...");
console.log(await contract.storage())
} catch (ex) {
console.log(ex)
}
}
async function example() {
const provider = 'https://alphanet-node.tzscan.io';
Tezos.setProvider({ rpc: provider });
try {
const op = await Tezos.tz.activate("tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu", "161d907951bf5594bedb1d70bb03c938d63c22be")
console.log('Awaiting confirmation...');
await op.confirmation();
console.log(op.hash, op.includedInBlock);
} catch (ex) {
console.log(ex)
}
}
"bring",
"ridge",
"traffic",
"initial",
"piece",
"annual",
"give",
"say",
"wrestle",
"rare",
"ability"
].join(" "), "7d4c8c3796fdbf4869edb5703758f0e5831f5081")
try {
console.log('Deploying Ligo simple contract...')
const op = await Tezos.contract.originate({
balance: "1",
code: ligoSample,
init: { int: "0" },
fee: 30000,
storageLimit: 2000,
gasLimit: 90000,
})
console.log('Awaiting confirmation...')
const contract = await op.contract()
console.log('Storage', await contract.storage())
console.log("Operation hash:", op.hash, "Included in block level:", op.includedInBlock)
} catch (ex) {
console.error(ex)
}
}