Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature-request] Caller witness creation #7

Closed
stskeeps opened this issue Jan 1, 2021 · 1 comment · Fixed by #12
Closed

[feature-request] Caller witness creation #7

stskeeps opened this issue Jan 1, 2021 · 1 comment · Fixed by #12
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@stskeeps
Copy link

stskeeps commented Jan 1, 2021

Document how to do a transfer w/ caller witness (smart contract)

@SilentCicero SilentCicero added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 2, 2021
@SilentCicero
Copy link
Member

SilentCicero commented Jan 7, 2021

@stskeeps this feature is on the way #12 and will become available in @fuel-js/wallet@0.5.2. We can experiment a bit with API's but this is the general format.

// Get the transaction Id for this transfer.
const txTokenId = 1;
const txAddress = '0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e';
const txAmount = utils.parseEther('1');

// Generate the transactionId for this transfer.
const transactionId = await wallet.transfer(txTokenId, txAddress, txAmount, {
    transactionId: true,
});

// Commit the witness, note the contract object can be used by any provider (web3/ethers)
// it just has to contact the `fuel` contract directly and use the `commitWitness(bytes32 transactionId)` ABI.
let commitTx = await wallet.contract.commitWitness(transactionId, {
    gasLimit: 200000,
});

// Here we wait for the transaction to process, but I also increased the number of blocks to let the Fuel aggregator pickup the log.
// We will likely want to add a checking step here (on a loop) to ensure the Fuel sequencer has picked up the witness commitment.
// For now just attempt to do the transfer until it goes through, but wait a few blocks to ensure the sequencer can pick it up, I selected 12 Ethereum blocks here, in ethers.js notation below.
commitTx = await commitTx.wait(12);

// Transfer using Caller witness.
await wallet.transfer(txTokenId, txAddress, txAmount, {
    // Here we provide the necessary event data to build the Caller witness (i.e. `{ blockNumber, address }`)
    caller: commitTx.events[0].args,
});

Anyway, should be in once the PR is reviewed / merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants