coinbase / coinbase-sdk-nodejs

Other
74 stars 28 forks source link

Support smart contract invocations #206

Closed alex-stone closed 2 months ago

alex-stone commented 2 months ago

What changed? Why?

This adds support for invoking a smart contract using MPC Wallets and developer-managed wallets.

Example of how to invoke a smart contract:

const wallet = await Wallet.create();

await wallet.faucet();

const abi = [
  {
    inputs: [{internalType: 'address', name: 'recipient', type: 'address'}],
    name: 'mint',
    outputs: [{internalType: 'uint256', name: '', type: 'uint256'}],
    stateMutability: 'payable',
    type: 'function'
  }
]

const contractInvocation = await wallet.getDefaultAddress.invokeContract({
  abi,
  method: "mint",
  contractAddress: '0xa82aB8504fDeb2dADAa3B4F075E967BbE35065b9',
  args: ['0x475d41de7A81298Ba263184996800CBcaAD73C0b']
});

await contractInvocation.wait();

Qualified Impact

alex-stone commented 2 months ago

:haircut: @John-peterson-coinbase

Changes